简体   繁体   English

如何使用Jenkinsfile更好地可视化大型构建步骤的工作?

[英]How can I better visualize the work of a large build step using a Jenkinsfile?

I have a pretty long build step (it takes hours) and a Jenkinsfile triggering it. 我有一个相当长的构建步骤(需要几个小时),并且有一个Jenkinsfile触发它。 (The build steps consists of multiple Makefile targets etc.) (构建步骤包括多个Makefile目标等)

Since the build step does everything needed to produce the artifact, the Jenkins Pipeline visualization is pretty useless. 由于构建步骤完成了生成工件所需的一切,因此Jenkins Pipeline可视化几乎没有用。

Is there a way how I can better visualize the internals of the build step without porting/duplicating it to a Jenkinsfile ? 有没有一种方法可以更好地可视化构建步骤的内部结构而无需将其移植/复制到Jenkinsfile?

You can move away from a single target task to build everything ( make or make all ) and instead specifically target different build tasks in the Jenkinsfile. 您可以离开单个目标任务来构建所有内容( makemake all ),而可以专门针对Jenkinsfile中的不同构建任务。 For example, let's say you're building an app for different platforms. 例如,假设您要为不同的平台构建应用程序。 Your original Jenkinsfile might be... 您最初的Jenkinsfile可能是...

node('builder') {
  stage('build') {
    sh "make"
  }
}

which was triggering the "all" target in your makefile, which might be triggering the tasks "iOS", "android", and "windowsphone" 这会触发您的makefile中的“所有”目标,这可能会触发任务“ iOS”,“ android”和“ windowsphone”

Instead, have your Jenkinsfile target each one of these make tasks individually. 相反,让您的Jenkinsfile分别针对每个make任务。

Ex: 例如:

node('builder') {
  stage('build iOS') {
    sh "make iOS"
  }
  stage('build android') {
    sh "make android"
  }
  stage('build windows phone') {
    sh "make windowsphone"
  }
}

By splitting up your target tasks into these multiple stages, you should better reporting in your Jenkins UI. 通过将目标任务划分为多个阶段,您应该更好地在Jenkins UI中进行报告。

If you wanted to be really brave, you could avoid hardcoding this in two places (the all target, and the Jenkinsfile) by creating a script to take apart what all was doing and turn it into jenkins stages. 如果您真的很勇敢,可以通过创建脚本来分解all工作并将其转变为jenkins阶段,从而避免在两个地方( all目标和Jenkinsfile)进行硬编码。 Assuming that your all or default task is just a list of other tasks, you can use the following bash: 假设您的all或默认任务只是其他任务的列表,则可以使用以下bash:

if [[ -z $(make -rpn | grep ".DEFAULT_GOAL") ]]; then
    DEFAULTTARGET=all
else
    DEFAULTTARGET=$(make -rpn | grep ".DEFAULT_GOAL" | sed "s/.*=[[:space:]]*//" | tr -d "[:space:]")
fi

make -rpn | sed -n -e "/^$/ { n ; /^[^ ]*:/p ; }" | grep "$DEFAULTTARGET:" | sed "s/.*:[[:space:]]*//" | tr " " "\n"

in a Jenkinsfile like so: 在这样的Jenkinsfile中:

node() {
    ## NOT NORMALLY REQUIRED. Just sets up a simple makefile
    sh "echo 'all: images release clean report' > Makefile "
    ## Start of required logic
    def makeTasks = sh(script: 'if [[ -z $(make -rpn | grep ".DEFAULT_GOAL") ]]; then     DEFAULTTARGET=all; else     DEFAULTTARGET=$(make -rpn | grep ".DEFAULT_GOAL" | sed "s/.*=[[:space:]]*//" | tr -d "[:space:]"); fi; make -rpn | sed -n -e "/^$/ { n ; /^[^ ]*:/p ; }" | grep "$DEFAULTTARGET:" | sed "s/.*:[[:space:]]*//" | tr " " "\n"', returnStdout: true)
    def tasks = makeTasks.split('\n')
    for(int i = 0; i < tasks.size(); i++ ){
        stage(tasks[i]) {
            echo tasks[i]
            // This will fail with the bogus makefile defined above, but would work with a real one.
            // sh 'make ${tasks[i]}'
        }
    }
}

Not really: there was a similar issue for long-running stages . 并非完全如此: 长时间运行阶段也存在类似问题

Regarding steps, there is JENKINS 33185 ("Visualize parallel steps within a Pipeline Stage") still open 关于步骤,仍有JENKINS 33185 (“可视化管道阶段中的并行步骤”)

But for one single long-running step, all you have is the shell output, which is not that helpful when a command takes a long time to complete. 但是对于一个单独的长时间运行的步骤,您所拥有的只是shell输出,当命令需要很长时间才能完成时,它就没有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何使用 cron 语法从 jenkinsfile 触发构建? - How i can trigger build from jenkinsfile using cron syntax? 我可以使用 Jenkinsfile 中的函数构建阶段吗? - Can I build stages with a function in a Jenkinsfile? 如何使用声明式 Jenkinsfile 构建 docker 镜像 - How to build docker images using a Declarative Jenkinsfile 如何使用 powereshell 在 Jenkinsfile 中打印当前工作目录 - How can I print the current working directory in a Jenkinsfile using powereshell 如何使用 jenkinsfile 将工件发布到 S3 存储桶? - How can i publish artifacts to S3 buckets using jenkinsfile? 如何使用Jenkinsfile在子目录中构建Dockerfile - How build a Dockerfile in a Subdirectory using a Jenkinsfile 在 Jenkinsfile 中,如何在同一个 Job 中运行另一个 Jenkinsfile? - In a Jenkinsfile, how can I run a another Jenkinsfile in the same Job? 如何从没有jenkinsfile的存储库触发Jenkins管道构建? - How can I have a Jenkins pipeline build be triggered from a repository with no jenkinsfile? 如何使用作业 dsl 向现有作业添加后期构建步骤? - How can i add a post build step to an existing job using job dsl? 使用Jenkins和/或Ant,如何在构建步骤后重命名目录? - Using Jenkins and/or Ant, how can I rename a directory after a build step?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM