[英]Find Jenkins job through command line
Currently I search with: 目前我搜索:
ps axf | grep jenkins
And see my job in this format: 以这种格式看我的工作:
51412 ? S 0:00 \_ /bin/sh -xe /var/lib/jenkins/tmp/jenkins2641742926206351383.sh
The job's name is GOOD_JOB 这份工作的名字是GOOD_JOB
How can I return jenkins2641742926206351383.sh based on GOOD_JOB only in the command line? 如何仅在命令行中返回基于GOOD_JOB的 jenkins2641742926206351383.sh ?
In other words, if I only have GOOD_JOB how do I return jenkins2641742926206351383.sh through command line? 换句话说,如果我只有GOOD_JOB,如何通过命令行返回jenkins2641742926206351383.sh ?
有可能更简单的方法来做到这一点,但你可以用这样的awk做到这一点:
ps axf | grep jenkins | awk -F'/' '{print $8}'
IIUC you want to "Find a Jenkins' build temporary build script name given a Job Name." IIUC你想“在给定一个工作名称的情况下找到一个Jenkins'构建临时构建脚本名称。” In the code below I assume you want the last build, or know the build number.
在下面的代码中,我假设您想要最后一次构建,或者知道构建号。
Jenkins has many APIs which might reveal this, but being an old CLI greybeard here's a quick bash recipe to 'grep' by pattern in the Jenkins build logs: Jenkins有许多API可能会揭示这一点,但作为一个旧的CLI greybeard,这是一个快速的bash配方,可以通过Jenkins构建日志中的模式'grep':
JENKINS_HOME=/path/to/Jenkins/home
find_jenkins_sh() {
local jobname bldnum log res
jobname=$1
bldnum=$2
### if we don't get a build number, find the latest one
if [ -z "$bldnum" ] ; then
bldnum=$(cd $JENKINS_HOME/jobs/$jobname/builds &&
/bin/ls -trd [0-9]* | tail -1)
fi
### now we can locate the log and grep for our pattern
local log=$JENKINS_HOME/jobs/$jobname/builds/$bldnum/log
res=$(grep -m1 jenkins[0-9]*.sh $log) # first mention: -m1
res=${res//*jenkins/jenkins} # strip up to 'jenkins'
echo "$log: $res"
}
# if you know the job number
find_jenkins_sh GOOD_JOB 1234
# use the last job number
find_jenkins_sh GOOD_JOB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.