流水线入门
Jenkins pipeline 打印环境变量, linux下用 printenv
, windows下用 set
sh printenv //linux
bat set // windows
全局变量参考 env
BRANCH_NAME=master
BUILD_DISPLAY_NAME=#13
BUILD_ID=13 //The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds
BUILD_NUMBER=13
BUILD_TAG=jenkins-OnCommit Test-GmainTest-master-13 //jenkins-${JOB_NAME}-${BUILD_NUMBER}
BUILD_URL=http://192.168.1.3:8080/job/OnCommit%20Test/job/GmainTest/job/master/13/
COMMITTER=COMMITTER
EXECUTOR_NUMBER=0 //The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
GIT_BRANCH=master
GIT_COMMIT=126f1c318d7a3c1ae804e0cf78aba9cd2443ce98
GIT_PREVIOUS_COMMIT=e4ec01df60c0ad4091395d04cdfe6f71e11111c7
GIT_PREVIOUS_SUCCESSFUL_COMMIT=42fffc17ebb8ea5ae3d58a733646f8bd7ee40a10
GIT_URL=****
JENKINS_HOME=C:\Program Files (x86)\Jenkins
JENKINS_URL=http://192.168.1.3:8080
JOB_URL=http://192.168.1.3:8080/job/OnCommit%20Test/job/GmainTest/job/master/
RUN_CHANGES_DISPLAY_URL=http://192.168.1.3:8080/job/OnCommit%20Test/job/GmainTest/job/master/13/display/redirect?page=changes
RUN_DISPLAY_URL=http://192.168.1.3:8080/job/OnCommit%20Test/job/GmainTest/job/master/13/display/redirect
WORKSPACE=C:\Program Files (x86)\Jenkins\workspace\OnCommit_Test_GmainTest_master</pre>
params
Exposes all parameters defined in the build as a read-only map with variously typed values. Example:
if (params.BOOLEAN_PARAM_NAME) {doSomething()}
or to supply a nontrivial default value:
if (params.getOrDefault('BOOLEAN_PARAM_NAME', true)) {doSomething()}
Note for multibranch (Jenkinsfile) usage: the properties step allows you to define job properties, but these take effect when the step is run, whereas build parameter definitions are generally consulted before the build begins. As a convenience, any parameters currently defined in the job which have default values will also be listed in this map. That allows you to write, for example:
properties([parameters([string(name: 'BRANCH', defaultValue: 'master')])])
git url: '…', branch: params.BRANCH
and be assured that the master branch will be checked out even in the initial build of a branch project, or if the previous build did not specify parameters or used a different parameter name.
currentBuild
number #build number (integer)
result #typically SUCCESS, UNSTABLE, or FAILURE (may be null for an ongoing build)
currentResult #typically SUCCESS, UNSTABLE, or FAILURE (may be null for an ongoing build)
resultIsBetterOrEqualTo(String) #Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is better than or equal to the provided result.
resultIsWorseOrEqualTo(String) #Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is worse than or equal to the provided result.
displayName #normally #123 but sometimes set to, e.g., an SCM commit identifier.
fullDisplayName #normally folder1 » folder2 » foo #123.
projectName #Name of the project of this build, such as foo.
fullProjectName #Full name of the project of this build, including folders such as folder1/folder2/foo.
description #additional information about the build
id #normally number as a string
absoluteUrl #URL of build index page
changeSets #a list of changesets coming from distinct SCM checkouts; each has a `kind` and is a list of commits; each commit has a `commitId`, `timestamp`, `msg`, `author`, and `affectedFiles` each of which has an `editType` and `path`; the value will not generally be `Serializable` so you may only access it inside a method marked `@NonCPS`
upstreamBuilds #a list of upstream builds. These are the builds of the upstream projects whose artifacts feed into this build.
Additionally, for this build only (but not for other builds), the following properties are writable:
- result
- displayName
- description
- keepLog