234cfds1 发表于 2018-1-6 20:59:54

Jenkins内置环境变量的使用

  一、查看Jenkins有哪些环境变量
  1、新建任意一个job
  2、增加构建步骤:Execute shell 或 Execute Windows batch command
  3、点击输入框下方的“可用环境变量”
https://images2015.cnblogs.com/blog/77835/201509/77835-20150922145817506-166888673.jpg
  4、可以看到有如下变量供使用:

变量名
解释
BUILD_NUMBER
The current build number, such as "153"
BUILD_ID
The current build>  二、使用Jenkins的内置变量
  1、在Execute shell 或 Execute Windows batch command文本框中使用,使用方法:%变量名%,如下图
https://images2015.cnblogs.com/blog/77835/201509/77835-20150922151351694-830552490.jpg
  2、结合Ant,在build.xml文件中使用:
  1、添加如下第4行代码:<property environment="env"/>
  2、使用方法:${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
  
10 </project>
  
页: [1]
查看完整版本: Jenkins内置环境变量的使用