简体   繁体   English

通过命令行查找Jenkins作业

[英]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.

相关问题 通过 Jenkins 执行 Groovy 命令:“查找:缺少‘-exec’的参数” - Executing Groovy command through Jenkins: "find: missing argument to `-exec'" 通过命令行运行时找不到或加载主类 - Could not find or load main class when running through command line “mvn:找不到命令”在 jenkins 作业中安装二进制文件,即使在正确设置环境变量后也能够在终端上找到版本“mvn -v” - "mvn: command not found" in jenkins job install binary even after setting environment variable properly able to find version "mvn -v" on terminal 詹金斯上没有显示TF命令行可执行文件 - TF Command Line Executable not showing up on Jenkins 如何从命令行重新加载配置 Jenkins? - How to reload the configuration Jenkins from the command line? 如何通过 jenkins 作业在 docker 中创建 httpd 容器? - How to create a httpd container in docker through jenkins job? 如何使 Jenkins 找到作业中指定的 shell 脚本 - How to make Jenkins find the shell script which is specified in the job 查找,替换或插入-命令行 - Find, Replace or Insert - command Line 查找命令可从命令行运行,但不能在脚本中运行 - Find command works from command line but not in a script 通过管道读取命令行参数到sh - reading command line arguments through pipe to sh
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM