Hudson/Jenkins--如何自定义build name

本文介绍如何使用DescriptionSetterPlugin及BuildNameSetter插件为Jenkins的任务构建赋予更有意义的名称,提升构建流程的可读性。

Hudson/Jenkins的job的默认的build name一般都是基于时间格式的,如何在给出一个比时间更具有意义的build name呢,可以利用以下2个插件:


Description Setter Plugin

下载地址:https://wiki.jenkins-ci.org/display/JENKINS/Description+Setter+Plugin

该plugin利用正则匹配,从console log中选取相应的字符串作为build name,如下图所示



Build Name Setter

下载地址:https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin

该plugin可以从job workspace的property file中读取对应的字段设置build name。因此,我们可以首先利用代码生成一个简单的property文件,其中定义好build version,然后做如下配置:


上图中,我们在job的第一步用代码生成一个build.txt的property文件,其中定义了一对key-value:buildversion=xxx;在Hudson/Jenkins中选择profile,文件名和要提取的property,但build结束时,该字段的值就会作为这个build的name。


01:42:32 Started by user Admin 01:42:32 Running as SYSTEM 01:42:32 Building on the built-in node in workspace E:\Jenkins\workspace\UE\5.5.4\Echo_BuildForUGS_01 01:42:32 Executor number at runtime: 0 01:42:32 ... p4 login + 01:42:32 ... p4 login -s + 17:33:14 ... p4 client -o Jenkins-Build-Echo-UE-5.5.4 + 17:33:14 ... p4 info + 17:33:14 ... p4 info + 17:33:14 ... p4 client -o Jenkins-Build-Echo-UE-5.5.4 + 17:33:15 ... p4 client -i + 17:33:15 ... View: + 17:33:15 ... p4 counter change + 17:33:15 ... p4 changes -m1 -ssubmitted //Jenkins-Build-Echo-UE-5.5.4/...@650 + 17:33:16 P4: found 650 revision in //Jenkins-Build-Echo-UE-5.5.4/...@650 17:33:16 ... p4 changes -m1 -ssubmitted //Jenkins-Build-Echo-UE-5.5.4/...@1,650 + 17:33:19 P4: found 650 revision in //Jenkins-Build-Echo-UE-5.5.4/...@1,650 17:33:19 ... p4 repos -C + 17:33:19 P4: builds: 650 17:33:19 ... p4 login + 17:33:19 ... p4 login -s + 17:33:19 ... p4 client -o Jenkins-Build-Echo-UE-5.5.4 + 17:33:19 ... p4 info + 17:33:19 ... p4 info + 17:33:19 ... p4 client -o Jenkins-Build-Echo-UE-5.5.4 + 17:33:19 17:33:19 P4 Task: establishing connection. 17:33:19 ... server: ssl:192.168.2.4:1668 17:33:19 ... node: a849e4696f69 17:33:19 Building on Node: built-in 17:33:19 ... p4 login + 17:33:19 ... p4 login -s + 17:33:19 ... p4 client -o Jenkins-Build-Echo-UE-5.5.4 + 17:33:19 ... p4 info + 17:33:19 ... p4 info + 17:33:19 ... p4 client -o Jenkins-Build-Echo-UE-5.5.4 + 17:33:19 17:33:19 P4 Task: establishing connection. 17:33:19 ... server: ssl:192.168.2.4:1668 17:33:19 ... node: a849e4696f69 17:33:19 17:33:19 P4 Task: reverting all pending and shelved revisions. 17:33:19 ... p4 revert E:\Jenkins\workspace\UE\5.5.4\Echo_BuildForUGS_01/... + 17:33:19 P4 Task: attempt: 1 01:33:22 ERROR: P4: Task Exception: hudson.AbortException: P4JAVA: Error(s): 01:33:22 Path '/E:\Jenkins\workspace\UE\5.5.4\Echo_BuildForUGS_01/...' is not under client's root 'E:\Jenkins\workspace\UE\5.5.4\Echo_BuildForUGS_01'. 01:33:22 01:33:25 Finished:
03-26
Running as SYSTEM Building on the built-in node in workspace /var/jenkins_home/workspace/Tapo_test [Tapo_test] $ /bin/sh -xe /tmp/jenkins4030103379424762008.sh + env JENKINS_HOME=/var/jenkins_home JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental CI=true RUN_CHANGES_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/7/display/redirect?page=changes HOSTNAME=45104600b3f3 NODE_LABELS=built-in SHLVL=0 HUDSON_URL=http://10.0.138.175/ HOME=/var/jenkins_home BUILD_URL=http://10.0.138.175/job/Tapo_test/7/ JENKINS_SERVER_COOKIE=b6155e08db5e2646 HUDSON_COOKIE=ea41a46d-1976-4e58-a6f7-581f13e8834d JENKINS_UC=https://updates.jenkins.io REF=/usr/share/jenkins/ref WORKSPACE=/var/jenkins_home/workspace/Tapo_test NODE_NAME=built-in RUN_ARTIFACTS_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/7/display/redirect?page=artifacts DOCKERFILE_LOCATION=dockerfile/ EXECUTOR_NUMBER=0 BUILD_DISPLAY_NAME=#7 JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals JENKINS_VERSION=2.516.3 RUN_TESTS_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/7/display/redirect?page=tests HUDSON_HOME=/var/jenkins_home JOB_BASE_NAME=Tapo_test PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin BUILD_ID=7 BUILD_TAG=jenkins-Tapo_test-7 LANG=C.UTF-8 JENKINS_URL=http://10.0.138.175/ JOB_URL=http://10.0.138.175/job/Tapo_test/ BUILD_NUMBER=7 JENKINS_SLAVE_AGENT_PORT=50000 RUN_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/7/display/redirect HUDSON_SERVER_COOKIE=b6155e08db5e2646 JOB_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/display/redirect JOB_NAME=Tapo_test COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log JAVA_HOME=/opt/java/openjdk PWD=/var/jenkins_home/workspace/Tapo_test WORKSPACE_TMP=/var/jenkins_home/workspace/Tapo_test@tmp + BRANCH_NAME=Tapo/H500 + which python3 Build step 'Execute shell' marked build as failure Archiving artifacts Stopping all containers Finished: FAILURE
12-25
Started by user Yilun Wu Running as SYSTEM Building on the built-in node in workspace /var/jenkins_home/workspace/Tapo_test [Tapo_test] $ /bin/sh -xe /tmp/jenkins6431093081201892627.sh + env JENKINS_HOME=/var/jenkins_home JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental CI=true RUN_CHANGES_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/5/display/redirect?page=changes HOSTNAME=45104600b3f3 NODE_LABELS=built-in SHLVL=0 HUDSON_URL=http://10.0.138.175/ HOME=/var/jenkins_home BUILD_URL=http://10.0.138.175/job/Tapo_test/5/ JENKINS_SERVER_COOKIE=b6155e08db5e2646 HUDSON_COOKIE=a4c855f7-07d4-4936-879f-ba66a76ca71d JENKINS_UC=https://updates.jenkins.io REF=/usr/share/jenkins/ref WORKSPACE=/var/jenkins_home/workspace/Tapo_test NODE_NAME=built-in RUN_ARTIFACTS_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/5/display/redirect?page=artifacts DOCKERFILE_LOCATION=dockerfile/ EXECUTOR_NUMBER=0 BUILD_DISPLAY_NAME=#5 JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals JENKINS_VERSION=2.516.3 RUN_TESTS_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/5/display/redirect?page=tests HUDSON_HOME=/var/jenkins_home JOB_BASE_NAME=Tapo_test PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin BUILD_ID=5 BUILD_TAG=jenkins-Tapo_test-5 LANG=C.UTF-8 JENKINS_URL=http://10.0.138.175/ JOB_URL=http://10.0.138.175/job/Tapo_test/ BUILD_NUMBER=5 JENKINS_SLAVE_AGENT_PORT=50000 RUN_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/5/display/redirect HUDSON_SERVER_COOKIE=b6155e08db5e2646 JOB_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/display/redirect JOB_NAME=Tapo_test COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log JAVA_HOME=/opt/java/openjdk PWD=/var/jenkins_home/workspace/Tapo_test WORKSPACE_TMP=/var/jenkins_home/workspace/Tapo_test@tmp + BRANCH_NAME=Tapo/H500 + command -v repo + echo Installing repo tool from Google... Installing repo tool from Google... + mkdir -p /var/jenkins_home/.bin + export PATH=/var/jenkins_home/.bin:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + curl https://storage.googleapis.com/git-repo-downloads/repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 44952 100 44952 0 0 297k 0 --:--:-- --:--:-- --:--:-- 296k + chmod a+rx /var/jenkins_home/.bin/repo + echo Repo tool installed successfully Repo tool installed successfully + [ ! -d .repo/repo ] + echo Repo not initialized or incomplete, setting up... Repo not initialized or incomplete, setting up... + rm -rf .repo CAMEOS#Remove Any dirs related to source code + NEED_INIT=true + git config --global user.name Jenkins CI + git config --global user.email jenkins@tp-link.com + git config --global color.ui false + export REPO_NO_SELF_UPDATE=1 + export GIT_TERMINAL_PROMPT=0 + export GIT_SSH_COMMAND=ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null + [ true = true ] + echo Running repo init (first time)... Running repo init (first time)... + repo init -u ssh://gerrit/manifests/CEE -b Tapo/H500 -m manifest.xml /usr/bin/env: ‘python3’: No such file or directory Build step 'Execute shell' marked build as failure Archiving artifacts Stopping all containers Finished: FAILURE
12-25
Started by user Yilun Wu Running as SYSTEM Building remotely on aws-test-agent in workspace /build/jenkins/workspace/Tapo_test [Tapo_test] $ /bin/sh -xe /tmp/jenkins7538228438322689453.sh + env JENKINS_HOME=/var/jenkins_home SSH_CLIENT=10.0.138.175 35804 22 USER=ubuntu CI=true RUN_CHANGES_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/12/display/redirect?page=changes XDG_SESSION_TYPE=tty NODE_LABELS=aws-test-agent SHLVL=0 HUDSON_URL=http://10.0.138.175/ HOME=/home/ubuntu OLDPWD=/home/ubuntu BUILD_URL=http://10.0.138.175/job/Tapo_test/12/ JENKINS_SERVER_COOKIE=b6155e08db5e2646 HUDSON_COOKIE=85d8cc3c-c9e5-44dc-9f70-6bed703cd934 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus WORKSPACE=/build/jenkins/workspace/Tapo_test LOGNAME=ubuntu NODE_NAME=aws-test-agent RUN_ARTIFACTS_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/12/display/redirect?page=artifacts DOCKERFILE_LOCATION=dockerfile/ _=/usr/bin/java XDG_SESSION_CLASS=user EXECUTOR_NUMBER=3 XDG_SESSION_ID=78 BUILD_DISPLAY_NAME=#12 RUN_TESTS_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/12/display/redirect?page=tests HUDSON_HOME=/var/jenkins_home JOB_BASE_NAME=Tapo_test PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin BUILD_ID=12 XDG_RUNTIME_DIR=/run/user/1000 BUILD_TAG=jenkins-Tapo_test-12 LANG=C.UTF-8 JENKINS_URL=http://10.0.138.175/ JOB_URL=http://10.0.138.175/job/Tapo_test/ BUILD_NUMBER=12 SHELL=/bin/bash RUN_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/12/display/redirect HUDSON_SERVER_COOKIE=b6155e08db5e2646 JOB_DISPLAY_URL=http://10.0.138.175/job/Tapo_test/display/redirect JOB_NAME=Tapo_test PWD=/build/jenkins/workspace/Tapo_test SSH_CONNECTION=10.0.138.175 35804 10.0.131.164 22 WORKSPACE_TMP=/build/jenkins/workspace/Tapo_test@tmp + BRANCH_NAME=Tapo/H500 + exit 0 [Tapo_test] $ /bin/bash /tmp/jenkins3730405176305069181.sh [Tapo_test] $ /bin/sh -xe /tmp/jenkins17343858980407599494.sh + echo === Preparing artifacts for Jenkins Archive Plugin === === Preparing artifacts for Jenkins Archive Plugin === + mkdir -p /build/jenkins/workspace/Tapo_test/artifacts + rm -rf /build/jenkins/workspace/Tapo_test/artifacts/* + cd CAMEOS/image/H500 /tmp/jenkins17343858980407599494.sh: 9: cd: can't cd to CAMEOS/image/H500 Build step 'Execute shell' marked build as failure Archiving artifacts Stopping all containers Finished: FAILURE
最新发布
12-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值