前言:
本文介紹插件: Parameterized Trigger plugin的具體使用方法。
一、插件介紹
Parameterized Trigger plugin插件可以讓你在構建完成時觸發新的Job構建,並以各種方式為新Job構建指定參數。
當然也可以添加多個配置:每個配置都有一個要觸發的Job,觸發時間的條件(基於當前構建的結果)和參數部分。
二、使用方法
1、項目Test_A,配置-構建后操作-配置如下信息:
選擇【Trigger parameterized build on other projects】
【Projects to build】:項目名稱
【Trigger when build is】:項目執行狀態
【Add Parameters】:添加需要傳的參數1、【Predefined parameters】:預定義參數,后續的job的入參與當前job的參數名稱不一致,或者有新參數的時候,可以使用該傳參方式。
局限:后續job的入參的值要么固定,要么由環境變量和入參進行簡單的組合獲取,無法融入邏輯語句。
2、【Current build parameters】:后續job的入參和用到當前job的入參的時候,可是使用該傳參方式。
局限:參數取決於當前的job
3、【Parameters from properties file】:若后續job的入參的值需要一定邏輯處理才能獲取,那么,這種傳參方式就特別好用了,比較靈活。
本次傳參例子為:JOB_NAME=${JOB_NAME}
2、項目Test_B,配置-參數化構建過程-配置如下信息:
選擇【參數化構建過程】
【添加參數-字符參數】:選擇字符參數
【名稱】:輸入參數名稱JOB_NAME
3、項目Test_B,輸出傳入的參數驗證。
選擇【構建-Execute shell】
輸出傳參:echo ${JOB_NAME}
4、執行項目Test_A后,自動執行項目Test_B,並傳入參數${JOB_NAME},查看項目Test_B輸出結果。
項目Test_B輸出結果如下:
三、預定義參數
我選擇的參數為預定義參數Predefined parameters,那分別有哪些預定義參數可以用呢?
在Build模塊下選擇Execute shell--the list of available environment variables 選項,可以查看預定義參數信息,如下圖:
如下,列出所有可用的預定義參數:
The following variables are available to shell scripts
BRANCH_NAME
For a multibranch project, this will be set to the name of the branch being built, for example in case you wish to deploy to production from master but not from feature branches; if corresponding to some kind of change request, the name is generally arbitrary (refer to CHANGE_ID and CHANGE_TARGET).
CHANGE_ID
For a multibranch project corresponding to some kind of change request, this will be set to the change ID, such as a pull request number, if supported; else unset.
CHANGE_URL
For a multibranch project corresponding to some kind of change request, this will be set to the change URL, if supported; else unset.
CHANGE_TITLE
For a multibranch project corresponding to some kind of change request, this will be set to the title of the change, if supported; else unset.
CHANGE_AUTHOR
For a multibranch project corresponding to some kind of change request, this will be set to the username of the author of the proposed change, if supported; else unset.
CHANGE_AUTHOR_DISPLAY_NAME
For a multibranch project corresponding to some kind of change request, this will be set to the human name of the author, if supported; else unset.
CHANGE_AUTHOR_EMAIL
For a multibranch project corresponding to some kind of change request, this will be set to the email address of the author, if supported; else unset.
CHANGE_TARGET
For a multibranch project corresponding to some kind of change request, this will be set to the target or base branch to which the change could be merged, if supported; else unset.
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 older builds
BUILD_DISPLAY_NAME
The display name of the current build, which is something like "#153" by default.
JOB_NAME
Name of the project of this build, such as "foo" or "foo/bar".
JOB_BASE_NAME
Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo".
BUILD_TAG
String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into 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 build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
NODE_NAME
Name of the agent if the build is on an agent, or "master" if run on master
NODE_LABELS
Whitespace-separated list of labels that the 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 this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set)
JOB_URL
Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set)
GIT_COMMIT
The commit hash being checked out.
GIT_PREVIOUS_COMMIT
The hash of the commit last built on this branch, if any.
GIT_PREVIOUS_SUCCESSFUL_COMMIT
The hash of the commit last successfully built on this branch, if any.
GIT_BRANCH
The remote branch name, if any.
GIT_LOCAL_BRANCH
The local branch name being checked out, if applicable.
GIT_URL
The remote URL. If there are multiple, will be GIT_URL_1, GIT_URL_2, etc.
GIT_COMMITTER_NAME
The configured Git committer name, if any.
GIT_AUTHOR_NAME
The configured Git author name, if any.
GIT_COMMITTER_EMAIL
The configured Git committer email, if any.
GIT_AUTHOR_EMAIL
The configured Git author email, if any.
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.
以上~ 如果對你有幫助的話,點贊❤️吧~~