Jenkins – Failed to get job details from upstream job – null object

I am having 2 jobs naming JobA and JobB. I try to print JobA last successful build number in JobB with following script

environment {
stages {
    stage('demo') {
        steps {
            script {
                def jenkins = Jenkins.getInstance()
                def jobName = "${DEV_PROJECT_NAME}"
                def job = jenkins.getItem(jobName)
                println "Last successfull build: ${job.getLastSuccessfulBuild()}"


However, I am constantly getting this error in console output, anything goes wrong?

java.lang.NullPointerException: Cannot invoke method
getLastSuccessfulBuild() on null object

Leave a Reply

Notify of