Build Properties - userId property?
Hello,
Do we have a build property which specifies the user who has requested a - personal - build? We need it to manage the output path for our build (we don't want personl builds to override other users' or the build user's build jar files etc) I tried ${userId} in the output path but it didn't work. We don't want to use propeties like the build label etc. in the output path because it'll be difficult to manage the output folders Thanks |
4 answers
Unfortunately, userId is not available as a property in the build.
Feel free to create an enhancement work item for this. https://jazz.net/jazz/web/projects/Jazz%20Project#action=com.ibm.team.workitem.newWorkItem |
I replied to this a while ago with the following message but apparently it
didn't go through because I attached the file. I've now pasted it in instead. "Attached is an ant task that I wrote for someone else who recently wanted similar functionality. This will get you the id of the requester of the build. There should already be a property defined automatically if it's a personal build so you should be able to use that to conditionally call this. You'll need to compile the file yourself and include the library on your ant class path. Also...this isn't officially supported so use at your own risk." Don Weinand Jazz Team Build /******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2008. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: * Use, duplication or disclosure restricted by GSA ADP Schedule * Contract with IBM Corp. *******************************************************************************/package com.ibm.team.build.unsupported.ant.task;import java.util.List;import org.apache.tools.ant.BuildException;import org.eclipse.osgi.util.NLS;import com.ibm.team.build.common.model.IBuildRequest;import com.ibm.team.build.common.model.IBuildRequestHandle;import com.ibm.team.build.common.model.IBuildResult;import com.ibm.team.build.common.model.IBuildResultHandle;import com.ibm.team.repository.client.IItemManager;import com.ibm.team.repository.common.IContributor;import com.ibm.team.repository.common.ItemNotFoundException;import com.ibm.team.repository.common.TeamRepositoryException;import com.ibm.team.repository.common.UUID;/** * Task for retrieving the user id of the contributor that requested abuild. * <p> * Required attributes are: * <p> * <ul> * <li><b>buildResultUUID</b> - The uuid of the build result.</li> * <li><b>requesterNameProperty</b> - The ant property to store the user idof * the contributor that requested the build.</li> * </ul> * <p> * <b>See {@link AbstractTeamBuildTask} for additional required and option * attributes.</b> * */public class GetBuildRequesterTask extends AbstractTeam BuildTask { /** * The ant attribute for this task in the ant script representing theuuid * of the build result. */ public static final String BUILD_RESULT_UUID = "buildResultUUID";//$NON-NLS-1$ /** * The ant attribute for this task in the ant script representing theuser id * of an ant property in which to store the name of the requester. */ public static final String REQUESTER_USERID_PROPERTY ="requesterUserIdProperty"; //$NON-NLS-1$ private String fBuildResultUUID = null; private String fRequesterUserIdProperty = null; /** * Set the uuid of the build result to update. * * @param buildResultUUID * The uuid of the build result to update. */ public void setBuildResultUUID(String buildResultUUID) { fBuildResultUUID = buildResultUUID; } /** * Set the of an ant property in which to store the user id of therequester. * * @param requesterUserIdProperty * an ant property in which to store the user id of therequester. */ public void setRequesterUserIdProperty(String requesterUserIdProperty) { fRequesterUserIdProperty = requesterUserIdProperty; } /* * (non-Javadoc) Intentionally not documented. See parent. */ @Override protected void collectAntAttributes(List antAttributes) { antAttributes.add(new UUIDAntAttribute(BUILD_RESULT_UUID,fBuildResultUUID, true)); antAttributes.add(new AntAttribute(REQUESTER_USERID_PROPERTY,fRequesterUserIdProperty, true)); } /* * (non-Javadoc) Intentionally not documented. See parent. */ @Override protected void doExecute() throws Exception { String userId = "UnknownRequester"; //$NON-NLS-1$ IBuildResult buildResult = getBuildResult(); List requests = buildResult.getBuildRequests(); if (requests.size() > 0) { IBuildRequestHandle buildRequestHandle = (IBuildRequestHandle)requests.get(0); IBuildRequest buildRequest = (IBuildRequest)getTeamRepository().itemManager().fetchCompleteItem( buildRequestHandle, IItemManager.REFRESH,getProgressMonitor()); IContributor contributor = (IContributor)getTeamRepository().itemManager().fetchCompleteItem( buildRequest.getInitiatingContributor(),IItemManager.REFRESH, getProgressMonitor()); userId = contributor.getUse rId(); } getProject().setProperty(fRequesterUserIdProperty, userId); if (isVerbose()) { log(NLS.bind("Build \"{0}\" was requested by \"{1}\".",buildResult.getLabel(), userId)); //$NON-NLS-1$ } } /** * Retrieves the <code>IBuildResult</code> associated with the build * result UUID for the task using the specified properties. * * @return the build result associated with the build result uuid forthe * task * @throws BuildException * If the existing build result could not be successfully * retrieved */ private IBuildResult getBuildResult() throws BuildException { try { IBuildResultHandle resultHandle = getBuildResultHandle(); return (IBuildResult)getTeamRepository().itemManager().fetchCompleteItem(resultHandle, IItemManager.REFRESH, getProgressMonitor()); } catch (ItemNotFoundException e) { throw new BuildException(NLS.bind("The \"{0}\" with id \"{1}\"could not be found.", //$NON-NLS-1$ IBuildResult.ITEM_TYPE.getName(), fBuildResultUUID), e); } catch (TeamRepositoryException e) { throw new BuildException(e); } } private IBuildResultHandle getBuildResultHandle() { return (IBuildResultHandle)IBuildResult.ITEM_TYPE.createItemHandle(UUID.valueOf(fBuildResultUUID),null); }}"saraf" <saraf> wrote in messagenews:gf775l$9q4$1@localhost.localdomain...> Hello,>> Do we have a build property which specifies the user who has requested> a - personal - build? We need it to manage the output path for our> build (we don't want personl builds to override other users' or the> build user's build jar files etc) I tried ${userId} in the output> path but it didn't work.>> We don't want to use propeties like the build label etc. in the output> path because it'll be difficult to manage the output folders>> Thanks> |
One more time...hopefully adding pre tags around it stops it from
formattting it crazy... <pre> /******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2008. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: * Use, duplication or disclosure restricted by GSA ADP Schedule * Contract with IBM Corp. *******************************************************************************/package com.ibm.team.build.unsupported.ant.task;import java.util.List;import org.apache.tools.ant.BuildException;import org.eclipse.osgi.util.NLS;import com.ibm.team.build.common.model.IBuildRequest;import com.ibm.team.build.common.model.IBuildRequestHandle;import com.ibm.team.build.common.model.IBuildResult;import com.ibm.team.build.common.model.IBuildResultHandle;import com.ibm.team.repository.client.IItemManager;import com.ibm.team.repository.common.IContributor;import com.ibm.team.repository.common.ItemNotFoundException;import com.ibm.team.repository.common.TeamRepositoryException;import com.ibm.team.repository.common.UUID;/** * Task for retrieving the user id of the contributor that requested abuild. * <p> * Required attributes are: * <p> * <ul> * <li><b>buildResultUUID</b> - The uuid of the build result.</li> * <li><b>requesterNameProperty</b> - The ant property to store the user idof * the contributor that requested the build.</li> * </ul> * <p> * <b>See {@link AbstractTeamBuildTask} for additional required and option * attributes.</b> * */public class GetBuildRequesterTask extends AbstractTeam BuildTask { /** * The ant attribute for this task in the ant script representing theuuid * of the build result. */ public static final String BUILD_RESULT_UUID = "buildResultUUID";//$NON-NLS-1$ /** * The ant attribute for this task in the ant script representing theuser id * of an ant property in which to store the name of the requester. */ public static final String REQUESTER_USERID_PROPERTY ="requesterUserIdProperty"; //$NON-NLS-1$ private String fBuildResultUUID = null; private String fRequesterUserIdProperty = null; /** * Set the uuid of the build result to update. * * @param buildResultUUID * The uuid of the build result to update. */ public void setBuildResultUUID(String buildResultUUID) { fBuildResultUUID = buildResultUUID; } /** * Set the of an ant property in which to store the user id of therequester. * * @param requesterUserIdProperty * an ant property in which to store the user id of therequester. */ public void setRequesterUserIdProperty(String requesterUserIdProperty) { fRequesterUserIdProperty = requesterUserIdProperty; } /* * (non-Javadoc) Intentionally not documented. See parent. */ @Override protected void collectAntAttributes(List antAttributes) { antAttributes.add(new UUIDAntAttribute(BUILD_RESULT_UUID,fBuildResultUUID, true)); antAttributes.add(new AntAttribute(REQUESTER_USERID_PROPERTY,fRequesterUserIdProperty, true)); } /* * (non-Javadoc) Intentionally not documented. See parent. */ @Override protected void doExecute() throws Exception { String userId = "UnknownRequester"; //$NON-NLS-1$ IBuildResult buildResult = getBuildResult(); List requests = buildResult.getBuildRequests(); if (requests.size() > 0) { IBuildRequestHandle buildRequestHandle = (IBuildRequestHandle)requests.get(0); IBuildRequest buildRequest = (IBuildRequest)getTeamRepository().itemManager().fetchCompleteItem( buildRequestHandle, IItemManager.REFRESH,getProgressMonitor()); IContributor contributor = (IContributor)getTeamRepository().itemManager().fetchCompleteItem( buildRequest.getInitiatingContributor(),IItemManager.REFRESH, getProgressMonitor()); userId = contributor.getUse rId(); } getProject().setProperty(fRequesterUserIdProperty, userId); if (isVerbose()) { log(NLS.bind("Build \"{0}\" was requested by \"{1}\".",buildResult.getLabel(), userId)); //$NON-NLS-1$ } } /** * Retrieves the <code>IBuildResult</code> associated with the build * result UUID for the task using the specified properties. * * @return the build result associated with the build result uuid forthe * task * @throws BuildException * If the existing build result could not be successfully * retrieved */ private IBuildResult getBuildResult() throws BuildException { try { IBuildResultHandle resultHandle = getBuildResultHandle(); return (IBuildResult)getTeamRepository().itemManager().fetchCompleteItem(resultHandle, IItemManager.REFRESH, getProgressMonitor()); } catch (ItemNotFoundException e) { throw new BuildException(NLS.bind("The \"{0}\" with id \"{1}\"could not be found.", //$NON-NLS-1$ IBuildResult.ITEM_TYPE.getName(), fBuildResultUUID), e); } catch (TeamRepositoryException e) { throw new BuildException(e); } } private IBuildResultHandle getBuildResultHandle() { return (IBuildResultHandle)IBuildResult.ITEM_TYPE.createItemHandle(UUID.valueOf(fBuildResultUUID),null); }}</pre>"Donald Weinand" <dmweinan> wrote in messagenews:ghma6l$pbu$1@localhost.localdomain...>I replied to this a while ago with the following message but apparently itdidn't go through because I attached the file. I've now pasted it ininstead.>> "Attached is an ant task that I wrote for someone else who recentlywanted> similar functionality. This will get you the id of the requester of the> build. There should already be a property defined automatically if it'sa> personal build so you should be able to use that to conditionally callthis.> You'll need to compile the file yourself and include the library on yourant> class path. Also...this isn't officially supported so use at your ownrisk.">> Don Weinand> Jazz Team Build>>/*******************************************************************************> * Licensed Materials - Property of IBM> * (c) Copyright IBM Corporation 2008. All Rights Reserved.> *> * Note to U.S. Government Users Restrict ed Rights:> * Use, duplication or disclosure restricted by GSA ADP Schedule> * Contract with IBM Corp.>*******************************************************************************/package com.ibm.team.build.unsupported.ant.task;importjava.util.List;import org.apache.tools.ant.BuildException;importorg.eclipse.osgi.util.NLS;importcom.ibm.team.build.common.model.IBuildRequest;importcom.ibm.team.build.common.model.IBuildRequestHandle;importcom.ibm.team.build.common.model.IBuildResult;importcom.ibm.team.build.common.model.IBuildResultHandle;importcom.ibm.team.repository.client.IItemManager;importcom.ibm.team.repository.common.IContributor;importcom.ibm.team.repository.common.ItemNotFoundException;importcom.ibm.team.repository.common.TeamRepositoryException;importcom.ibm.team.repository.common.UUID;/** * Task for retrieving the user id ofthe contributor that requested abuild. * <p> * Required attributes are: *<p> * <ul> * <li><b>buildResultUUID</b> - The uuid of the build result.</li>* <li><b>requesterNameProperty</b> - The ant property to store the user idof* the contributor that requested the build.</li> * </ul> * <p> * <b>See{@link AbstractTeamBuildTask} for additional required an d option *attributes.</b> * */public class GetBuildRequesterTask extendsAbstractTeamBuildTask { /** * The ant attribute for this task in theant script representing theuuid * of the build result. */ publicstatic final String BUILD_RESULT_UUID = "buildResultUUID";//$NON-NLS-1$/** * The ant attribute for this task in the ant script representingtheuser id * of an ant property in which to store the name of therequester. */ public static final String REQUESTER_USERID_PROPERTY="requesterUserIdProperty"; //$NON-NLS-1$ private String fBuildResultUUID= null; private String fRequesterUserIdProperty = null; /** * Setthe uuid of the build result to update. * * @param buildResultUUID* The uuid of the build result to update. */ public voidsetBuildResultUUID(String buildResultUUID) { fBuildResultUUID =buildResultUUID; } /** * Set the of an ant property in which tostore the user id of therequester. * * @paramrequesterUserIdProperty * an ant property in which to storethe user id of therequester. */ public voidsetRequesterUserIdProperty(String requesterUserIdProperty) {fRequesterUse rIdProperty = requesterUserIdProperty; } /* *(non-Javadoc) Intentionally not documented. See parent. */ @Overrideprotected void collectAntAttributes(List antAttributes) {antAttributes.add(new UUIDAntAttribute(BUILD_RESULT_UUID,fBuildResultUUID,true)); antAttributes.add(newAntAttribute(REQUESTER_USERID_PROPERTY,fRequesterUserIdProperty,e)); } /* * (non-Javadoc) Intentionally not documented. Seeparent. */ @Override protected void doExecute() throws Exception{ String userId = "UnknownRequester"; //$NON-NLS-1$IBuildResult buildResult = getBuildResult(); List requests =buildResult.getBuildRequests(); if (requests.size() > 0){ IBuildRequestHandle buildRequestHandle =(IBuildRequestHandle)requests.get(0); IBuildRequest buildRequest=(IBuildRequest)getTeamRepository().itemManager().fetchCompleteItem(buildRequestHandle, IItemManager.REFRESH,getProgressMonitor());IContributor contributor =(IContributor)getTeamRepository().itemManager().fetchCompleteItem(buildRequest.getInitiatingContributor(),IItemManager.REFRESH,getProgressMonitor()); userId = contributor.getUserId(); }getProject().setPro perty(fRequesterUserIdProperty, userId); if(isVerbose()) { log(NLS.bind("Build \"{0}\" was requested by\"{1}\".",buildResult.getLabel(), userId)); //$NON-NLS-1$ } }/** * Retrieves the <code>IBuildResult</code> associated with the build* result UUID for the task using the specified properties. * *@return the build result associated with the build result uuid forthe *task * @throws BuildException * If the existing buildresult could not be successfully * retrieved */private IBuildResult getBuildResult() throws BuildException { try{ IBuildResultHandle resultHandle = getBuildResultHandle();return(IBuildResult)getTeamRepository().itemManager().fetchCompleteItem(resultHandle, IItemManager.REFRESH, getProgressMonitor()); }catch (ItemNotFoundException e) { throw newBuildException(NLS.bind("The \"{0}\" with id \"{1}\"could not be found.",//$NON-NLS-1$ IBuildResult.ITEM_TYPE.getName(),fBuildResultUUID), e); } catch (TeamRepositoryException e){ throw new BuildException(e); } } privateIBuildResultHandle getB uildResultHandle() { return(IBuildResultHandle)IBuildResult.ITEM_TYPE.createItemHandle(UUID.valueOf(fBuildResultUUID),null); }}"saraf" <saraf>wrote in messagenews:gf775l$9q4$1@localhost.localdomain...> Hello,>> Do wehave a build property which specifies the user who has requested> a -personal - build? We need it to manage the output path for our> build (wedon't want personl builds to override other users' or the> build user'sbuild jar files etc) I tried ${userId} in the output> path but it didn'twork.>> We don't want to use propeties like the build label etc. in theoutput> path because it'll be difficult to manage the output folders>>Thanks>> |
Ok...new strategy since I can't get it stop butchering the format. I logged
and an enhancement with the file attached. https://jazz.net/jazz/web/projects/Jazz%20Project#action=com.ibm.team.workitem.viewWorkItem&id=65619 Don Weinand Jazz Team Build "Donald Weinand" <dmweinan> wrote in message news:ghmbqm$q52$1@localhost.localdomain... One more time...hopefully adding pre tags around it stops it from |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.