jenkins使用大全

部署

jenkins 相關網站

Jenkins官網:https://jenkins.io/
Jenkins官網文檔:https://www.jenkins.io/zh/doc/
Jenkins學習文檔:https://www.w3cschool.cn/jenkins/jenkins-5h3228n2.html
jenkins安裝包:http://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/
OpenJDK:http://jdk.java.net/java-se-ri/11
清華鏡像:https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/

環境準備

關閉防火牆、SELinux

jenkins是使用java寫的程序,所以運行jenkins需要java環境
jenkins需要到gitlab上面拉取代碼,所以需要安裝git
jenkins如果有故障,需要發郵件報警,所以需要安裝postfix和mailx程序
postfix是發郵件的郵件服務器程序,mailx是收取郵件的客戶端軟件

[root@jenkins ~]# yum -y install git java-11-openjdk postfix mailx
[root@jenkins ~]# systemctl enable postfix
[root@jenkins ~]# systemctl start postfix

安裝jenkins

訪問地址,找個版本,然後下載,用來安裝

wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.438-1.1.noarch.rpm

[root@jenkins ~]# yum -y install ./jenkins-2.358-1.1.noarch.rpm 
[root@jenkins ~]# systemctl start jenkins.service 
[root@jenkins ~]# systemctl enable jenkins.service

 

登錄web頁面

firefox瀏覽器訪問Jenkins頁面(http://192.168.4.30:8080)
第一次訪問會提示初始密碼的位置,粘貼到網頁中,點擊《繼續》

[root@mcw15 ~]#  cat /var/lib/jenkins/secrets/initialAdminPassword 
d7a29acac7404f3bb888a431069f8a51
[root@mcw15 ~]# 

http://10.0.0.25:8080/

 

 

 

 

 

 插件管理

默認Jenkins是英文界面,如果需要中文需要安裝中文插件
默認Jenkins不支持git,需要安裝插件支持Git
插件下載地址:https://github.com/metersphere/jenkins-plugin/releases
注意:Jenkins存放插件的目錄是固定的:/var/lib/jenkins/plugins/,

[root@jenkins ~]# ls
anaconda-ks.cfg  jenkins-2.358-1.1.noarch.rpm  jenkins-plugin-1.20.9-lts-rc.tar.gz
[root@jenkins ~]# yum -y install tar
[root@jenkins ~]# tar -xf jenkins-plugin-1.20.9-lts-rc.tar.gz 
[root@jenkins ~]# cp -rp jenkins-plugin-1.20.9-lts-rc
jenkins-plugin-1.20.9-lts-rc/        jenkins-plugin-1.20.9-lts-rc.tar.gz  
[root@jenkins ~]# cp -rp jenkins-plugin-1.20.9-lts-rc/* /var/lib/jenkins/plugins/  # -p代表保留權限
[root@jenkins ~]# systemctl restart jenkins.service 

目前沒有已經安裝的插件

 從這裏安裝,不過好像沒有安裝按鈕

 從這裏找個https://github.com/metersphere/jenkins-plugin/releases

 下載之後,上傳然後重啓

[root@mcw15 ~]# ls
anaconda-ks.cfg  jenkins-2.438-1.1.noarch.rpm  jenkins-plugin-2.10.9-lts.tar.gz  mcwkeys  mcwkeys.tar.gz  original-ks.cfg
[root@mcw15 ~]# tar xf jenkins-plugin-2.10.9-lts.tar.gz 
[root@mcw15 ~]# ls
anaconda-ks.cfg  jenkins-2.438-1.1.noarch.rpm  jenkins-plugin-2.10.9-lts  jenkins-plugin-2.10.9-lts.tar.gz  mcwkeys  mcwkeys.tar.gz  original-ks.cfg
[root@mcw15 ~]# ls jenkins-plugin-2.10.9-lts
Jenkinsfile  LICENSE  mvnw  mvnw.cmd  pom.xml  README.md  src
[root@mcw15 ~]# ls jenkins-plugin-2.10.9-lts/src/
main
[root@mcw15 ~]# ls jenkins-plugin-2.10.9-lts/src/main/
java  resources
[root@mcw15 ~]# cp -a jenkins-plugin-2.10.9-lts/* /var/lib/jenkins/plugins/
[root@mcw15 ~]# ls /var/lib/jenkins/plugins/
Jenkinsfile  LICENSE  mvnw  mvnw.cmd  pom.xml  README.md  src
[root@mcw15 ~]# systemctl restart jenkins.service
[root@mcw15 ~]# 

重新登錄

 

 

 沒啥區別

 我們從其它地方弄來一些Jenkins插件包

[root@mcw15 ~]# ls 
anaconda-ks.cfg  jenkins-2.438-1.1.noarch.rpm  jenkins-plugin-2.10.9-lts  jenkins-plugin-2.10.9-lts.tar.gz  mcwjenkinsprodpluginsbak.tar.gz  mcwkeys  mcwkeys.tar.gz  original-ks.cfg
[root@mcw15 ~]# 
[root@mcw15 ~]# ls mcwjenkinsprodpluginsbak.tar.gz 
mcwjenkinsprodpluginsbak.tar.gz
[root@mcw15 ~]# tar xf mcwjenkinsprodpluginsbak.tar.gz
[root@mcw15 ~]# rm -rf /var/lib/jenkins/plugins/*
[root@mcw15 ~]# cp -a  plugins/* /var/lib/jenkins/plugins/
[root@mcw15 ~]# systemctl restart jenkins

然後再看,有些可以,有些插件不可以用

 並且已經有了中文的插件,可以顯示中文了

 

就到這裏吧,後面的再補充

參考:https://blog.csdn.net/m0_63674789/article/details/125723869

創建第一個pipeline

 

 

 

 

 暫時不用配置其它,只需要這裏填入pipeline內容,寫完之後應用

pipeline {
    agent any
    states('Build') {
        steps {
            echo 'Hello world'
        }
    }
}

 

 

 此項目已經禁用

另外一個也是禁用的

 

 進入配置,點擊成爲開啓了的,然後點擊應用

 就解除禁用了

 也可以用命令來開啓項目,不過需要先配置一個token

 

 

 

 112eac1050a879243a3d35336ebc8bdec4

curl -X POST 'http://<JENKINS_URL>/job/<JOB_NAME>/enable' \
--user <USERNAME>:<API_TOKEN>
 

目前是禁用,生成開啓命令

curl -X POST 'http://10.0.0.25:8080/job/mmm/enable' \
--user machangwei:112eac1050a879243a3d35336ebc8bdec4

 

 執行:

[root@mcw15 ~]# curl -X POST 'http://10.0.0.25:8080/job/mmm/enable' \
> --user machangwei:112eac1050a879243a3d35336ebc8bdec4
[root@mcw15 ~]# 

查看已經開啓

 執行,將這個pipeline項目也開啓

[root@mcw15 ~]# curl -X POST 'http://10.0.0.25:8080/job/pipeline-hello-world/enable' \
> --user machangwei:112eac1050a879243a3d35336ebc8bdec4
[root@mcw15 ~]# 

然後點擊立即構建

 報錯了,查看下日誌

 看到,語法寫錯了,我們用上面地址,然後用token請求一下試試,是不是能獲取到什麼,那個1,是第一次構建,指的是

 

執行後獲取到一個頁面

 複製粘貼到一個文件裏面,然後訪問一下試試

 可以看到輸出的日誌,但是頁面樣式有點問題

 我們改正語法,把states改正爲stages,然後應用和構建

 

 

 這個流水線的,不知道爲啥在頁面開啓沒有生效,只能用命令再次開啓

[root@mcw15 ~]# curl -X POST 'http://10.0.0.25:8080/job/pipeline-hello-world/enable' \
> --user machangwei:112eac1050a879243a3d35336ebc8bdec4
[root@mcw15 ~]# 

再次構建

 還是有報錯

 

 錯誤的寫法,

pipeline {
    agent any
    stages ('Build') {
        steps {
            echo 'Hello world'
        }
    }
}

下面纔是正確的寫法

pipeline {
    agent any
    
    stages {
        stage ('Build') {
            steps {
                echo 'Hello world'
            }
        }
    }
}

再次查看,構建成功了

 查看構建日誌

 沒找到這個目錄,可能是自動刪除了吧

 

 

手動創建一個普通的Jenkins項目,執行shell腳本,獲取系統變量 

打印環境變量

新增執行shell構建步驟

輸入命令應用

 立即構建

 獲取到工作目錄,查看環境變量

 

 我們將上面打印的變量寫在下面,和終端執行的命令對比下

Started by user 馬昌偉
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/test-env-var
[test-env-var] $ /bin/sh -xe /tmp/jenkins8006061449316534742.sh
+ pwd
/var/lib/jenkins/workspace/test-env-var
+ echo 'env var =====>'
env var =====>
+ printenv
BUILD_URL=http://10.0.0.25:8080/job/test-env-var/1/
HUDSON_SERVER_COOKIE=b318ad38d4dc712d
SHELL=/bin/false
BUILD_TAG=jenkins-test-env-var-1
WORKSPACE=/var/lib/jenkins/workspace/test-env-var
JOB_URL=http://10.0.0.25:8080/job/test-env-var/
RUN_CHANGES_DISPLAY_URL=http://10.0.0.25:8080/job/test-env-var/1/display/redirect?page=changes
USER=jenkins
RUN_ARTIFACTS_DISPLAY_URL=http://10.0.0.25:8080/job/test-env-var/1/display/redirect?page=artifacts
JENKINS_HOME=/var/lib/jenkins
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
RUN_DISPLAY_URL=http://10.0.0.25:8080/job/test-env-var/1/display/redirect
PWD=/var/lib/jenkins/workspace/test-env-var
HUDSON_URL=http://10.0.0.25:8080/
LANG=en_US.UTF-8
JOB_NAME=test-env-var
BUILD_DISPLAY_NAME=#1
JENKINS_URL=http://10.0.0.25:8080/
BUILD_ID=1
NOTIFY_SOCKET=/run/systemd/notify
JOB_BASE_NAME=test-env-var
RUN_TESTS_DISPLAY_URL=http://10.0.0.25:8080/job/test-env-var/1/display/redirect?page=tests
SHLVL=1
HOME=/var/lib/jenkins
CI=true
EXECUTOR_NUMBER=0
JENKINS_SERVER_COOKIE=b318ad38d4dc712d
WORKSPACE_TMP=/var/lib/jenkins/workspace/test-env-var@tmp
NODE_LABELS=built-in
LOGNAME=jenkins
HUDSON_HOME=/var/lib/jenkins
NODE_NAME=built-in
JOB_DISPLAY_URL=http://10.0.0.25:8080/job/test-env-var/display/redirect
BUILD_NUMBER=1
HUDSON_COOKIE=988cdd36-5526-455b-8947-e4938161fe83
_=/usr/bin/printenv
Finished: SUCCESS

好像是在root的系統環境變量基礎上,新增了很多變量,跟構建項目相關的信息。

[root@mcw15 test-env-var]# printenv
XDG_SESSION_ID=1
HOSTNAME=mcw15
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=10.0.0.1 59306 22
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/var/lib/jenkins/workspace/test-env-var
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=10.0.0.1 59306 10.0.0.25 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/usr/bin/printenv
OLDPWD=/root
[root@mcw15 test-env-var]# 

 shell框裏面引用變量

echo $HOME
echo $JENKINS_HOME
echo $JOB_NAME
echo $BUILD_NUMBE
echo $WORKSPACE
echo $BUILD_UR
echo $PWD
echo $JENKINS_URL

 可以看到,在這裏引用的時候,已經是變量所代替的值了

 修改

 如下,需要加斜線,才能不被轉爲變量。變量也可以花括號括起來

 shell腳本里設置變量和引用變量

 創建目錄和腳本

[root@mcw15 jenkins]# mkdir scripts
[root@mcw15 jenkins]# cd scripts/
[root@mcw15 scripts]# ls
[root@mcw15 scripts]# vim mcw.py
[root@mcw15 scripts]# vim mcw.sh
[root@mcw15 scripts]# pwd
/var/lib/jenkins/scripts
[root@mcw15 scripts]# cat mcw.sh 
echo $JOB_NAME
[root@mcw15 scripts]# 

填寫shell

export scriptsPath='scripts/mcw.sh'
myname='machagnwei'

sh $JENKINS_HOME/$scriptsPath
echo $myname
printenv|grep myname
printenv|grep scriptsPath

 執行如下,不能用管道,加上轉義符也不行

 

 加了export的,可以進入環境變量

 不加export的,只在shell這個框裏用,沒有進入環境變量,也就無法在shell腳本里面調用

 

[root@mcw15 scripts]# cat mcw.sh
echo $JOB_NAME
[root@mcw15 scripts]#

 

shell腳本里面能直接調用環境變量,所以想要在腳本里面使用Jenkins配置shell框框裏定義的變量,那麼用export讓它加入到環境變量,不加只是在框框裏臨時生效。

 python腳本里如何獲取以及寫入環境變量

 

[root@mcw15 scripts]# vim mcw.py
[root@mcw15 scripts]# pwd
/var/lib/jenkins/scripts
[root@mcw15 scripts]# cat mcw.py 
import os
os.environ["myname"] = "machangwei"
print(os.environ["myage"])
print("print os.environ =======> ")
print(os.environ)
[root@mcw15 scripts]# 

 執行

 如下,myage已經設置進去了,python腳本里面可以獲取到了,並且python腳本里面也成功往環境變量裏設置了myname

 python SDK構建Jenkins任務 參數化構建,傳參以及腳本中使用傳參

import jenkins

server = jenkins.Jenkins('http://10.0.0.25:8080/', username="machangwei", password="123456")
params={"pushlish_id":4,"action":"deploy"}
res=server.build_job('test-env-var' , parameters=params)
print(res)

 

 現在要執行python腳本,進行這個項目的第九次構建任務,並且沒有參數化構建的

 執行構建,沒有帶參數

 代碼構建。有麼有做個判斷,獲取這個項目,不存在就創建然後構建,存在就構建

 項目配置裏面沒有設置參數,但是代碼調用構建項目任務的時候帶參數,就報錯了,可以 看到請求的地址後面有拼接這兩個參數

requests.exceptions.HTTPError: 500 Server Error: Server Error for url: http://10.0.0.25:8080/job/test-env-var/buildWithParameters?pushlis_id=4&action=deploy

jenkins.JenkinsException: Error in request. Possibly authentication failed [500]: Server Error

 我們這裏暫時先添加字符參數和選項參數兩個

 添加第一個,然後再添加第二個

 選項參數。我們還可以傳是否是k8s部署等等之類的參數

 這裏還是沒有變。也就是這裏,除了參數和shell這裏有配置,其它都沒有做設置

 這個python腳本變了。我們要在python腳本里面獲取這些傳參,然後腳本里可以根據傳參來進行打包還是部署等行爲。

[root@mcw15 scripts]# vim mcw.py 
[root@mcw15 scripts]# pwd
/var/lib/jenkins/scripts
[root@mcw15 scripts]# cat mcw.py 
import os,sys
class CICD:
    def __init__(self):
        pass
    def __call__(self, *args, **kwargs):
        print("args:  ",args)
        print("kwargs:",kwargs)
if __name__ == "__main__":
    print("sys.argv: ",sys.argv)
    CICD()(*sys.argv)
    print("os.environ: ",os.environ)
[root@mcw15 scripts]# 

此時我們再次腳本調用Jenkins構建項目任務

 還是報錯,這裏有個token,我們也加個試試

 就添加這個的試試

 添加了不行,查看了下配置,我們設置的參數沒有保存,重新設置下,並改下shell,在shell裏面也打印一下這兩個參數

 保存之後,發現沒有保存上參數設置。查看了下,可能是沒有勾選,勾選上參數化構建過程,然後再次應用,結果的確是已經成本保存這兩個參數的配置了

 再次執行,執行成功了

 這裏這樣也是行的,返回的數字不知道是啥,先不管了

 我們看下控制檯輸出,先看shell框裏面引用參數

 可以看到引正常,可以引用到

 

再看下執行的python腳本里面如何引用參數化構建時的參數的,這個參數執行腳本命令行拼接參數,而是直接在腳本里面用,就像是在命令行已經添加了這個參數似的。

 根據下面輸出,我們可以看到Jenkins項目配置頁面shell框裏面執行腳本,參數化構建時,將參數放到環境變量裏了,如果你想從sys.argv或者參數,也估計也是得python執行腳本時,獲取,腳本名稱是第一個參數,你也可以添加參數action,這樣來把第二個參數當做要做的操作。 python $JENKINS_HOME/scripts/mcw.py $action

也就是我們用這種方式創建Jenkins構建任務,傳遞的參數,在環境變量裏面可以獲取到,如果腳本里面想用,可以從環境變量獲取

 修改下腳本,從環境變量裏獲取參數化構建中的傳參

 再次調用Jenkins對象,參數化構建任務執行一次,我們可以看到,三種獲取方式都可以正常從參數化構建中獲取到傳遞的參數。

 

import jenkins

server = jenkins.Jenkins('http://10.0.0.25:8080/', username="machangwei", password="123456")
params={"pushlish_id":4,"action":"deploy"}
res=server.build_job('test-env-var' , parameters=params)
print(res)

 

 

 

 

 

 

Jenkins裏可以獲取到的跟項目相關的環境變量有哪些

具體的是否能獲取到,還是得看能打印出來的環境變量吧

 http://10.0.0.25:8080/env-vars.html/

 

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).
BRANCH_IS_PRIMARY
For a multibranch project, if the SCM source reports that the branch being built is a primary branch, this will be set to "true"; else unset. Some SCM sources may report more than one branch as a primary branch while others may not supply this information.
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.
CHANGE_BRANCH
For a multibranch project corresponding to some kind of change request, this will be set to the name of the actual head on the source control system which may or may not be different from BRANCH_NAME. For example in GitHub or Bitbucket this would have the name of the origin branch whereas BRANCH_NAME would be something like PR-24.
CHANGE_FORK
For a multibranch project corresponding to some kind of change request, this will be set to the name of the forked repo if the change originates from one; else unset.
TAG_NAME
For a multibranch project corresponding to some kind of tag, this will be set to the name of the tag being built, if supported; else unset.
TAG_TIMESTAMP
For a multibranch project corresponding to some kind of tag, this will be set to a timestamp of the tag in milliseconds since Unix epoch, if supported; else unset.
TAG_UNIXTIME
For a multibranch project corresponding to some kind of tag, this will be set to a timestamp of the tag in seconds since Unix epoch, if supported; else unset.
TAG_DATE
For a multibranch project corresponding to some kind of tag, this will be set to a timestamp in the format as defined by java.util.Date#toString() (e.g., Wed Jan 1 00:00:00 UTC 2020), if supported; else unset.
JOB_DISPLAY_URL
URL that will redirect to a Job in a preferred user interface
RUN_DISPLAY_URL
URL that will redirect to a Build in a preferred user interface
RUN_ARTIFACTS_DISPLAY_URL
URL that will redirect to Artifacts of a Build in a preferred user interface
RUN_CHANGES_DISPLAY_URL
URL that will redirect to Changelog of a Build in a preferred user interface
RUN_TESTS_DISPLAY_URL
URL that will redirect to Test Results of a Build in a preferred user interface
CI
Statically set to the string "true" to indicate a "continuous integration" execution environment.
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 "built-in" if run on the built-in node (or "master" until Jenkins 2.306).
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.
WORKSPACE_TMP
A temporary directory near the workspace that will not be browsable and will not interfere with SCM checkouts. May not initially exist, so be sure to create the directory as needed (e.g., mkdir -p on Linux). Not defined when the regular workspace is a drive root.
JENKINS_HOME
The absolute path of the directory assigned on the controller file system 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_CHECKOUT_DIR
The directory that the repository will be checked out to. This contains the value set in Checkout to a sub-directory, if used.
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, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.name Value field of the Jenkins Configure System page.
GIT_AUTHOR_NAME
The configured Git author name, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.name Value field of the Jenkins Configure System page.
GIT_COMMITTER_EMAIL
The configured Git committer email, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.email Value field of the Jenkins Configure System page.
GIT_AUTHOR_EMAIL
The configured Git author email, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.email Value field of the Jenkins Configure System page.

上面頁面中的第一個就不在我們打印的環境變量裏面,應該是因爲,我們這裏沒有指定代碼倉庫吧,畢竟看名字就是代碼倉庫的分支名字

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

參考:https://blog.csdn.net/m0_63674789/article/details/125723869

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章