Jenkins pass environment variables to ant scripts

Source: Internet
Author: User

First, see what environment variables are Jenkins

1. Create any Job

2. Add build steps: Execute shell or execute Windows batch command

3, click on the "Available environment variables" below the input box

4, you can see the following variables for use:

Variable name Explain
Build_number The current build number, such as "153"
build_id The current build ID, identical to Build_number for builds created in 1.597+, but a yyyy-mm-dd_hh-mm-ss timestamp for olde R Builds
Build_display_name The display name of the current build, which are something like ' #153 ' by default.
Job_name Name of the project of this build, such as "foo" or "Foo/bar". (To strip off folder paths from a Bourne shell script, try: ${job_name##*/})
Build_tag String of "Jenkins-${job_name}-${build_number}". Convenient to put in a resource file, a jar file, etc for easier identification.
Executor_number The unique number that identifies the "current executor" (among executors of the same machine) that's carrying out this Buil D. This is the number for you to the "Build executor status" of except that number starts from 0, not 1.
Node_name Name of the slave if the is on a slave, or "master" if run on master
Node_labels whitespace-separated List of labels that's node is assigned.
WORKSPACE The absolute path of the directory assigned to the build as a workspace.
Jenkins_home The absolute path of the directory assigned on the master node for Jenkins to store data.
Jenkins_url Full URL of Jenkins, like http://server:port/jenkins/(note:only available if Jenkins URL set in System configuration)
Build_url Full URL of ' build ' like http://server:port/jenkins/job/foo/15/(Jenkins URL must is set)
Svn_revision Subversion revision number that ' s currently checked out to the workspace, such as "12345"
Svn_url Subversion URL that ' s currently checked out to the workspace.
Job_url Full URL ' This job ' like http://server:port/jenkins/job/foo/(Jenkins URL must is set)

Second, the use of Jenkins built-in variables

1, in the Execute Shell or execute Windows Batch command text box, use the method:% variable name%, the following figure

  

2, combine ant, use in Build.xml file:

1, add the following 4th line of code: <property environment= "env"/>

2, use method: ${env. WORKSPACE}

1 <?xml version= "1.0" encoding= "UTF-8"?>
 2 
 3 <project name= "ant-test" default= "Run" basedir= "." >
 4     <property environment= "env"/>
 5     
 6     <target name= "clean" >
 7         < mkdir dir= "${env. Workspace}/results/${env. build_id} "/>
 8     </target>
 9 
</project>
3 can also give ant build.xml file pass parameters in the Ant plug-in configuration Name=value can be used when passing multiple parameters in Build.xml use, ${name} can be used directly
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.