Reputation: 107090
A quick question, but probably one that doesn't have an answer (or at least an answer I want):
I want to only import a specific set of environment variables into an Ant script. I know I can import the entire environment via the <property environment="env"/>
task. However, I'm using Jenkins and it just seems silly to import the whole environment because I want a couple of variables like $BUILD_NUMER
and $JOB_NAME
I know I could do something like this:
$ ant -DBUILD_NUMBER=$BUILD_NUMBER package
I thought someone might have figured out a way to do this via a resource collection. If not, I'll just have to accept the fact that all environment variables are imported.
Upvotes: 2
Views: 303
Reputation: 78215
Possibly cheating ... use a scriptdef
?
<scriptdef name="envproperty" language="javascript">
<attribute name="name" />
<attribute name="fromenv" />
<![CDATA[
importClass( java.lang.System );
project.setProperty(
attributes.get( "name" ),
System.getenv( attributes.get( "fromenv" ) )
);
]]>
</scriptdef>
<envproperty name="BUILD_NUMBER" fromenv="BUILD_NUMBER" />
<envproperty name="JOB_NAME" fromenv="JOB_NAME" />
Upvotes: 1