2

I have a pretty long build step (it takes hours) and a Jenkinsfile triggering it. (The build steps consists of multiple Makefile targets etc.)

Since the build step does everything needed to produce the artifact, the Jenkins Pipeline visualization is pretty useless.

Is there a way how I can better visualize the internals of the build step without porting/duplicating it to a Jenkinsfile ?

JE42
  • 4,881
  • 6
  • 41
  • 51

2 Answers2

3

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. For example, let's say you're building an app for different platforms. Your original Jenkinsfile might be...

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"

Instead, have your Jenkinsfile target each one of these make tasks individually.

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.

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. Assuming that your all or default task is just a list of other tasks, you can use the following 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:

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]}'
        }
    }
}
Spencer Malone
  • 1,449
  • 12
  • 12
0

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

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The ticket links to Blue Ocean (which I also have access to) but I am not sure how Blue Ocean can help. Regarding shell output. I have tons of it. It would be great if I could parse it and generate from the parsed output steps in the overview. But I haven't seen how I would do this. – JE42 May 21 '17 at 16:31
  • @JE42 Maybe through a plugin like https://wiki.jenkins-ci.org/display/JENKINS/Log+Parser+Plugin or more recently https://wiki.jenkins-ci.org/display/JENKINS/Console+Parser+Plugin, but it might not play well with pipelines. – VonC May 21 '17 at 16:32
  • @JE42 Or https://wiki.jenkins-ci.org/display/JENKINS/Text-finder+Plugin mentioned in https://chris-lamb.co.uk/posts/parsing-jenkins-log-output-determine-job-status, but that would be set as a separate job, which is not what your question seems to consider. – VonC May 21 '17 at 16:35
  • Unfortunately, all three plugins do not seem to be able to generate pipeline steps based on the console output. – JE42 May 21 '17 at 16:47
  • 1
    @JE42 Exactly, I didn't find an approach that would be a good fit as a pipeline step – VonC May 21 '17 at 16:48