Jenkins job failed but Octopus step shows task success

Hi ,

I am Prabhjot and working on Octopus. I am using Jenkins - Queue job step from community step.
Everything is working fine but even if the Jenkins job fail Octopus shows it as passed. Do I need to add any more step to get the Jenkins job status in Octopus.

Thanks,
Prabhjot

Hi @prabhjotkour.91,

Thanks for reaching out, I’m sorry that the step isn’t working as you would expect. I just had a quick look at the community step template that you are using.

The reason it may not be ‘failing’ the job is because in the source code, it looks to be using this logic:

    if ($failBuild) {
        if ($result -ne "SUCCESS") {
            Write-Host "BUILD FAILURE: build is unsuccessful or status could not be obtained."
            exit 1
        }

The problem with that code is, it will “Write-host” on failure. If you are receiving the message regarding “Build Failures” you should be able to update the “Write-host” command to “Write-error”, which will cause Octopus to fail the step. For more information, check out this documentation

Let me know how that goes.

Regards,
Dane

Hi Dane - thanks for your reply but it’s not clear to me. Do we have functionality in octopus to check the status of Jenkins job automatically and behave pass or fail accordingly. If not do we have to add extra functionality within our Jenkins groovy code?

Hi @prabhjotkour.91,

There isn’t anything built into Octopus that would probe the Jenkins Server however you still have some options.

First of all, if it’s just the build result you’re after, a simple api call could suffice. You can get the latest documentation on your specific version of Jenkins via built in documentation available at ‘https://YOUR_JENKINS_SERVER:8080/job/A_VALID_JOB/api/’

You may get some more ideas from this BLOG post.

To clarify, once you determine the call to the api for the build you are chasing - you would be able to make the call from a Script step using Powershell (or whatever language you want). You would then set the result as an Octopus Variable.

You would then be able to determine if you want your next Octopus step to run or not using a conditional run value.

Alternatively, we have a recommended approach, but it may not be possible for your pipeline/implementation. It would be to push the Build Information to Octopus from Jenkins itself. Your final Jenkins step for the project could be to ‘Push Build Information’ or ‘Push the Package’ (if an package is created) to your Octopus Server or your Package repository. This means Octopus would only be able to act upon ‘successful’ builds. I won’t go into too much detail, because it might not be the right option for you, however if you want more information, please check out this page.

I’m sorry this wasn’t the answer you were chasing, but hopefully it will provide some valid options for you.

Regards.

Dane

Hi Dane,

Thanks for suggesting the steps.

So if I don’t use Jenkins - queue step and instead use script step and add the below attached bash script will it work or I need to do any changes in this code.

Please let me know.

Thanks,
Prabhjot

Hi @prabhjotkour.91,

Your script is definitely one solution. You could use the bash argument “fail_step” as explained here to fail out of the process when it matches “$JOB_STATUS2”.

Another solution (which may or may not be acceptable for your case) might be to use OctopusDeployCreateRelease and an auto deploying lifecycle. So after Jenkins completes what it needs to do, it will trigger Octopus Deploy to Create a Release - and the Auto Deploy Environment Lifecycle will deploy the project.

This would mean that you have to rely on Conditional Steps in Jenkins to run. i.e The last step in the Jenkins Project would be a “Conditional Step” that will kick off the Octopus Deploy Release if all previous steps passed.

The benefit about the last option, is not having to rely on a continually running script probing your Jenkins server. There is definitely a few ways to tackle this problem, and I’ll be here if you need anymore guidance.

Please let me know how you go.

Regards,

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.