Jenkins- job之間傳參

前言:

本文介紹插件: Parameterized Trigger plugin的具體使用方法。node


1、插件介紹

Parameterized Trigger plugin插件可讓你在構建完成時觸發新的Job構建,並以各類方式爲新Job構建指定參數。
固然也能夠添加多個配置:每一個配置都有一個要觸發的Job,觸發時間的條件(基於當前構建的結果)和參數部分。shell


2、使用方法

一、項目Test_A,配置-構建後操做-配置以下信息:app

選擇【Trigger parameterized build on other projects】ide

【Projects to build】:項目名稱
【Trigger when build is】:項目執行狀態
【Add Parameters】:添加須要傳的參數ui

一、【Predefined parameters】:預約義參數,後續的job的入參與當前job的參數名稱不一致,或者有新參數的時候,可使用該傳參方式。
侷限:後續job的入參的值要麼固定,要麼由環境變量和入參進行簡單的組合獲取,沒法融入邏輯語句。
二、【Current build parameters】:後續job的入參和用到當前job的入參的時候,但是使用該傳參方式。
侷限:參數取決於當前的job
三、【Parameters from properties file】:若後續job的入參的值須要必定邏輯處理才能獲取,那麼,這種傳參方式就特別好用了,比較靈活。
image.png本次傳參例子爲:JOB_NAME=${JOB_NAME}this

二、項目Test_B,配置-參數化構建過程-配置以下信息:spa

選擇【參數化構建過程】插件

【添加參數-字符參數】:選擇字符參數
【名稱】:輸入參數名稱JOB_NAME
image.png3d

三、項目Test_B,輸出傳入的參數驗證。server

選擇【構建-Execute shell】

輸出傳參:echo ${JOB_NAME}
image.png

四、執行項目Test_A後,自動執行項目Test_B,並傳入參數${JOB_NAME},查看項目Test_B輸出結果。

項目Test_B輸出結果以下:
image.png


3、預約義參數

我選擇的參數爲預約義參數Predefined parameters,那分別有哪些預約義參數能夠用呢?

在Build模塊下選擇Execute shell--the list of available environment variables 選項,能夠查看預約義參數信息,以下圖:
image.png

以下,列出全部可用的預約義參數:

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. ---- 以上~ 若是對你有幫助的話,點贊❤️吧~~

相關文章
相關標籤/搜索