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
How can I return jenkins2641742926206351383.sh based on GOOD_JOB only in the command line?
In other words, if I only have GOOD_JOB how do I return jenkins2641742926206351383.sh through command line?
有可能更简单的方法来做到这一点,但你可以用这样的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." 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_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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.