天天看點

Jenkins- job之間傳參前言:

前言:

本文介紹插件:

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的入參的值需要一定邏輯處理才能擷取,那麼,這種傳參方式就特别好用了,比較靈活。

Jenkins- job之間傳參前言:
本次傳參例子為:JOB_NAME=${JOB_NAME}

2、項目Test_B,配置-參數化建構過程-配置如下資訊:

選擇【參數化建構過程】

【添加參數-字元參數】:選擇字元參數

【名稱】:輸入參數名稱JOB_NAME

Jenkins- job之間傳參前言:

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

選擇【建構-Execute shell】
輸出傳參:echo ${JOB_NAME}
Jenkins- job之間傳參前言:

4、執行項目Test_A後,自動執行項目Test_B,并傳入參數${JOB_NAME},檢視項目Test_B輸出結果。

項目Test_B輸出結果如下:
Jenkins- job之間傳參前言:

三、預定義參數

我選擇的參數為預定義參數Predefined parameters,那分别有哪些預定義參數可以用呢?

在Build子產品下選擇Execute shell--the list of available environment variables 選項,可以檢視預定義參數資訊,如下圖:
Jenkins- job之間傳參前言:

如下,列出所有可用的預定義參數:

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/

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.

----

以上~ 如果對你有幫助的話,點贊️吧~~

作者:

擱淺

出處:

http://www.cnblogs.com/xiaoxi-3-/

如果對您有幫助,請關注我的同名簡書:

https://www.jianshu.com/u/da1677475c27

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利。