It's all about the answers!

Ask a question

Build Properties - userId property?


Sara Forghanizadeh (12) | asked Nov 09 '08, 12:36 p.m.
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



permanent link
Ryan Manwiller (1.3k1) | answered Nov 10 '08, 1:08 p.m.
JAZZ DEVELOPER
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

permanent link
Don Weinand (7851) | answered Dec 09 '08, 12:38 p.m.
JAZZ DEVELOPER
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. * &lt;p&gt; * Required attributes are: * &lt;p&gt; * &lt;ul&gt; * &lt;li&gt;<b>buildResultUUID</b> - The uuid of the build result.&lt;/li&gt; * &lt;li&gt;<b>requesterNameProperty</b> - The ant property to store the user idof * the contributor that requested the build.&lt;/li&gt; * &lt;/ul&gt; * &lt;p&gt; * <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 = &quot;buildResultUUID&quot;;//$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 =&quot;requesterUserIdProperty&quot;; //$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 = &quot;UnknownRequester&quot;; //$NON-NLS-1$ IBuildResult buildResult = getBuildResult(); List requests = buildResult.getBuildRequests(); if (requests.size() &gt; 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(&quot;Build \&quot;{0}\&quot; was requested by \&quot;{1}\&quot;.&quot;,buildResult.getLabel(), userId)); //$NON-NLS-1$ } } /** * Retrieves the &lt;code&gt;IBuildResult&lt;/code&gt; 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(&quot;The \&quot;{0}\&quot; with id \&quot;{1}\&quot;could not be found.&quot;, //$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); }}&quot;saraf&quot; &lt;saraf&gt; wrote in messagenews:gf775l$9q4$1@localhost.localdomain...&gt; Hello,&gt;&gt; Do we have a build property which specifies the user who has requested&gt; a - personal - build? We need it to manage the output path for our&gt; build (we don't want personl builds to override other users' or the&gt; build user's build jar files etc) I tried ${userId} in the output&gt; path but it didn't work.&gt;&gt; We don't want to use propeties like the build label etc. in the output&gt; path because it'll be difficult to manage the output folders&gt;&gt; Thanks&gt;

permanent link
Don Weinand (7851) | answered Dec 09 '08, 1:08 p.m.
JAZZ DEVELOPER
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. * &lt;p&gt; * Required attributes are: * &lt;p&gt; * &lt;ul&gt; * &lt;li&gt;<b>buildResultUUID</b> - The uuid of the build result.&lt;/li&gt; * &lt;li&gt;<b>requesterNameProperty</b> - The ant property to store the user idof * the contributor that requested the build.&lt;/li&gt; * &lt;/ul&gt; * &lt;p&gt; * <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 = &quot;buildResultUUID&quot;;//$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 =&quot;requesterUserIdProperty&quot;; //$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 = &quot;UnknownRequester&quot;; //$NON-NLS-1$ IBuildResult buildResult = getBuildResult(); List requests = buildResult.getBuildRequests(); if (requests.size() &gt; 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(&quot;Build \&quot;{0}\&quot; was requested by \&quot;{1}\&quot;.&quot;,buildResult.getLabel(), userId)); //$NON-NLS-1$ } } /** * Retrieves the &lt;code&gt;IBuildResult&lt;/code&gt; 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(&quot;The \&quot;{0}\&quot; with id \&quot;{1}\&quot;could not be found.&quot;, //$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>&quot;Donald Weinand&quot; &lt;dmweinan&gt; wrote in messagenews:ghma6l$pbu$1@localhost.localdomain...&gt;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.&gt;&gt; &quot;Attached is an ant task that I wrote for someone else who recentlywanted&gt; similar functionality. This will get you the id of the requester of the&gt; build. There should already be a property defined automatically if it'sa&gt; personal build so you should be able to use that to conditionally callthis.&gt; You'll need to compile the file yourself and include the library on yourant&gt; class path. Also...this isn't officially supported so use at your ownrisk.&quot;&gt;&gt; Don Weinand&gt; Jazz Team Build&gt;&gt;/*******************************************************************************&gt; * Licensed Materials - Property of IBM&gt; * (c) Copyright IBM Corporation 2008. All Rights Reserved.&gt; *&gt; * Note to U.S. Government Users Restrict
ed Rights:&gt; * Use, duplication or disclosure restricted by GSA ADP Schedule&gt; * Contract with IBM Corp.&gt;*******************************************************************************/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. * &lt;p&gt; * Required attributes are: *&lt;p&gt; * &lt;ul&gt; * &lt;li&gt;<b>buildResultUUID</b> - The uuid of the build result.&lt;/li&gt;* &lt;li&gt;<b>requesterNameProperty</b> - The ant property to store the user idof* the contributor that requested the build.&lt;/li&gt; * &lt;/ul&gt; * &lt;p&gt; * <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 = &quot;buildResultUUID&quot;;//$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=&quot;requesterUserIdProperty&quot;; //$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 = &quot;UnknownRequester&quot;; //$NON-NLS-1$IBuildResult buildResult = getBuildResult(); List requests =buildResult.getBuildRequests(); if (requests.size() &gt; 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(&quot;Build \&quot;{0}\&quot; was requested by\&quot;{1}\&quot;.&quot;,buildResult.getLabel(), userId)); //$NON-NLS-1$ } }/** * Retrieves the &lt;code&gt;IBuildResult&lt;/code&gt; 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(&quot;The \&quot;{0}\&quot; with id \&quot;{1}\&quot;could not be found.&quot;,//$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); }}&quot;saraf&quot; &lt;saraf&gt;wrote in messagenews:gf775l$9q4$1@localhost.localdomain...&gt; Hello,&gt;&gt; Do wehave a build property which specifies the user who has requested&gt; a -personal - build? We need it to manage the output path for our&gt; build (wedon't want personl builds to override other users' or the&gt; build user'sbuild jar files etc) I tried ${userId} in the output&gt; path but it didn'twork.&gt;&gt; We don't want to use propeties like the build label etc. in theoutput&gt; path because it'll be difficult to manage the output folders&gt;&gt;Thanks&gt;&gt;

permanent link
Don Weinand (7851) | answered Dec 09 '08, 1:28 p.m.
JAZZ DEVELOPER
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&amp;id=65619

Don Weinand
Jazz Team Build

&quot;Donald Weinand&quot; &lt;dmweinan&gt; wrote in message
news:ghmbqm$q52$1@localhost.localdomain...
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. * &lt;p&gt; * Required attributes are:
* &lt;p&gt; * &lt;ul&gt; * &lt;li&gt;<b>buildResultUUID</b> - The uuid of the build
result.&lt;/li&gt; * &lt;li&gt;<b>requesterNameProperty</b> - The ant property to
store the user idof * the contributor that requested the build.&lt;/li&gt; *
/ul&gt; * &lt;p&gt; * <b>See {@link AbstractTeamBuildTask} for additional required
and option * attributes.</b> * */public class GetBuildRequesterTask
extends AbstractTeamBuildTask { /** * The ant attribute for this
task in the ant script representing theuuid * of the build result.
*/ public static final String BUILD_RESULT_UUID =
&quot;buildResultUUID&quot;;//$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 =&quot;requesterUserIdProperty&quot;; //$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,
e)); } /* * (non-Javadoc) Intentionally not documented. See
parent. */ @Override protected void doExecute() throws Exception
{ String userId = &quot;UnknownRequester&quot;; //$NON-NLS-1$
IBuildResult buildResult = getBuildResult(); List requests =
buildResult.getBuildRequests(); if (requests.size() &gt; 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 =
utor.getUserId(); }
getProject().setProperty(fRequesterUserIdProperty, userId); if
(isVerbose()) { log(NLS.bind(&quot;Build \&quot;{0}\&quot; was requested by
\&quot;{1}\&quot;.&quot;,buildResult.getLabel(), userId)); //$NON-NLS-1$ } }
/** * Retrieves the &lt;code&gt;IBuildResult&lt;/code&gt; 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(&quot;The \&quot;{0}\&quot; with id \&quot;{1}\&quot;could not be found.&quot;,
//$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>&quot;Donald Weinand&quot; &lt;dmweinan&gt; wrote in
messagenews:ghma6l$pbu$1@localhost.localdomain...&gt;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.&gt;&gt; &quot;Attached is
an ant task that I wrote for someone else who recentlywanted&gt; similar
functionality. This will get you the id of the requester of the&gt; 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.&gt; You'll need to compile the file yourself and include the
library on yourant&gt; class path. Also...this isn't officially supported so
use at your ownrisk.&quot;&gt;&gt; Don Weinand&gt; Jazz Team
Build&gt;&gt;/*******************************************************************************
* Licensed Materials - Property of IBM&gt; * (c) Copyright IBM Corporation
2008. All Rights Reserved.&gt; *&gt; * Note to U.S. Government Users Restricted
Rights:&gt; * Use, duplication or disclosure restricted by GSA ADP Schedule
* Contract with IBM
Corp.&gt;*******************************************************************************/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.
* &lt;p&gt; * Required attributes are: *&lt;p&gt; * &lt;ul&gt; *
li&gt;<b>buildResultUUID</b> - The uuid of the build result.&lt;/li&gt;*
li&gt;<b>requesterNameProperty</b> - The ant property to store the user
idof* the contributor that requested the build.&lt;/li&gt; * &lt;/ul&gt; * &lt;p&gt; *
b&gt;See{@link AbstractTeamBuildTask} for additional required and 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 =
&quot;buildResultUUID&quot;;//$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=&quot;requesterUserIdProperty&quot;; //$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)
{fRequesterUserIdProperty = 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 = &quot;UnknownRequester&quot;; //$NON-NLS-1$IBuildResult buildResult
= getBuildResult(); List requests =buildResult.getBuildRequests();
if (requests.size() &gt; 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 =
utor.getUserId(); }getProject().setProperty(fRequesterUserIdProperty,
userId); if(isVerbose()) { log(NLS.bind(&quot;Build \&quot;{0}\&quot;
was requested by\&quot;{1}\&quot;.&quot;,buildResult.getLabel(), userId));
NLS-1$ } }/** * Retrieves the &lt;code&gt;IBuildResult&lt;/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(&quot;The \&quot;{0}\&quot; with id \&quot;{1}\&quot;could not be
found.&quot;,//$NON-NLS-1$
IBuildResult.ITEM_TYPE.getName(),fBuildResultUUID), e); } catch
(TeamRepositoryException e){ throw new
ception(e); } } privateIBuildResultHandle
getBuildResultHandle() {
return(IBuildResultHandle)IBuildResult.ITEM_TYPE.createItemHandle(UUID.valueOf(fBuildResultUUID),null);
}}&quot;saraf&quot; &lt;saraf&gt;wrote in
messagenews:gf775l$9q4$1@localhost.localdomain...&gt; Hello,&gt;&gt; Do wehave a
build property which specifies the user who has requested&gt; a -personal -
build? We need it to manage the output path for our&gt; build (wedon't want
personl builds to override other users' or the&gt; build user'sbuild jar
files etc) I tried ${userId} in the output&gt; path but it didn'twork.&gt;&gt; We
don't want to use propeties like the build label etc. in theoutput&gt; path
because it'll be difficult to manage the output folders&gt;&gt;Thanks

Your answer


Register or to post 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.