[JIRA] (JENKINS-61265) Job with Extensible Groovy script does NOT get latest value when triggered by another job

24 views
Skip to first unread message

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 7:40:05 PM2/27/20
to jenkinsc...@googlegroups.com
Chris Fouts created an issue
 
Jenkins / Bug JENKINS-61265
Job with Extensible Groovy script does NOT get latest value when triggered by another job
Issue Type: Bug Bug
Assignee: ikedam
Components: extensible-choice-parameter-plugin
Created: 2020-02-28 00:39
Environment: Jenkins v2.164.3
Extensible Choice Parameter plugin v1.6.0
Priority: Critical Critical
Reporter: Chris Fouts

I have 2 Jenkins jobs, Job1 and Job2, and Job1 triggers Job2 via this pipeline DSL

node('someNode') {
 stage('Call Job2') {
   build job: 'Job2',
         parameters: [
           new StringParameterValue('ExtensibleChoiceParam',
                                    'TARGET_VERSION')
         ],
         wait: false
 }
}

 
Job2 has this Groovy script as its Extensible Choice Parameter for variable {{TARGET_VALUE, }}which provides a list of ALL successful builds for Job1

// code placeholder
import hudson.model.*
 
BUILD_JOB_NAME = "Job1"
 
def getBuildJob() {
    def buildJob = null
    Hudson.instance.getAllItems(Job.class).each {
        if (it.fullName == BUILD_JOB_NAME) {
            buildJob = it
        }
    }
    return buildJob
}
 
List<String> getAllBuildNumbers(Job job) {
        List<String> buildNumbers = []
        (job.getBuilds()).each {
            def status = it.getBuildStatusSummary().message
            if (status.contains("stable") || status.contains("normal")) {
                buildNumbers.add(it.displayName)
            }
        }
        return buildNumbers
}
 
Job buildJob = getBuildJob()
List<String> buildNumbers = null
if (buildJob) {
  buildNumbers = getAllBuildNumbers(buildJob)
}
return buildNumbers

Job2 does nothing but prints TARGET_VERSION, so it just does this

node('someNode') {
  stage('Print TARGET_VERSION') {
    println "TARGET_VERSION: $TARGET_VERSION"
  }
}

If Job1 has the following build history for example,

Build#    Status
$4        Success
#3        Fail
#2        Success
#1        Fail

 
If I click on Job2's Build with parameters link, I get the correct list, that is, as shown below, so I know the script is correct.

#4
#2

When Job1 triggers Job2 (per Job1's pipeline DSL above), I expect Job2 to print #4, Job1's latest successful build. However, it prints out #2, the previous successful build. Why?

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 7:41:03 PM2/27/20
to jenkinsc...@googlegroups.com
Chris Fouts updated an issue
Change By: Chris Fouts
I have 2 Jenkins jobs, Job1 and Job2, and Job1 triggers Job2 via this pipeline DSL
{code:java}

node('someNode') {
stage('Call Job2') {
   build job: 'Job2',
         parameters: [
           new StringParameterValue('ExtensibleChoiceParam',
                     'TARGET_VERSION')
         ],
         wait: false
}
}{code}
 
Job2 has this Groovy script as its Extensible Choice Parameter for variable
\ {{TARGET_VALUE , }} , which provides a list of ALL successful builds for Job1
{code:java}

// code placeholder
import hudson.model.*

BUILD_JOB_NAME = "Job1"

def getBuildJob() {
    def buildJob = null
    Hudson.instance.getAllItems(Job.class).each {
        if (it.fullName == BUILD_JOB_NAME) {
            buildJob = it
        }
    }
    return buildJob
}

List<String> getAllBuildNumbers(Job job) {
        List<String> buildNumbers = []
        (job.getBuilds()).each {
            def status = it.getBuildStatusSummary().message
            if (status.contains("stable") || status.contains("normal")) {
                buildNumbers.add(it.displayName)
            }
        }
        return buildNumbers
}

Job buildJob = getBuildJob()
List<String> buildNumbers = null
if (buildJob) {
  buildNumbers = getAllBuildNumbers(buildJob)
}
return buildNumbers
{code}

Job2 does nothing but prints TARGET_VERSION, so it just does this
{code:java}

node('someNode') {
  stage('Print TARGET_VERSION') {
    println "TARGET_VERSION: $TARGET_VERSION"
  }
}{code}

If Job1 has the following build history for example,
{noformat}

Build#    Status
$4        Success
#3        Fail
#2        Success
#1        Fail{noformat}

 
If I click on Job2's Build with parameters link, I get the correct list, that is, as shown below, so I know the script is correct.
{noformat}
#4
#2
{noformat}

When Job1 triggers Job2 (per Job1's pipeline DSL above), I expect Job2 to print {{#4}}, Job1's latest successful build. However, it prints out {{#2}}, the previous successful build. Why?

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 7:42:03 PM2/27/20
to jenkinsc...@googlegroups.com
Chris Fouts updated an issue
Change By: Chris Fouts
Attachment: Screen Shot 2020-02-27 at 7.29.52 AM.png

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 8:39:02 PM2/27/20
to jenkinsc...@googlegroups.com
Chris Fouts updated an issue
Change By: Chris Fouts
Attachment: Screen Shot 2020-02-27 at 8.36.13 PM.png

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 8:39:03 PM2/27/20
to jenkinsc...@googlegroups.com
Chris Fouts updated an issue
Change By: Chris Fouts
Attachment: Screen Shot 2020-02-27 at 8.34.53 PM.png

devld@ikedam.jp (JIRA)

unread,
Feb 27, 2020, 8:41:02 PM2/27/20
to jenkinsc...@googlegroups.com
ikedam updated Bug JENKINS-61265
 
Change By: ikedam
Status: Open Fixed but Unreleased
Resolution: Not A Defect

devld@ikedam.jp (JIRA)

unread,
Feb 27, 2020, 8:42:02 PM2/27/20
to jenkinsc...@googlegroups.com
ikedam assigned an issue to Chris Fouts
 

I failed to change the assignee.
Please see the previous comment.

Change By: ikedam
Assignee: ikedam Chris Fouts

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 8:54:03 PM2/27/20
to jenkinsc...@googlegroups.com
Chris Fouts commented on Bug JENKINS-61265
 
Re: Job with Extensible Groovy script does NOT get latest value when triggered by another job

Here's Job2's Extensible Choice Groovy script

import hudson.model.*
 
BUILD_JOB_NAME = "Utilities/Playground/Job1"
 
def getBuildJob() {
    def buildJob = null
    Hudson.instance.getAllItems(Job.class).each {
        if (it.fullName == BUILD_JOB_NAME) {
            buildJob = it
        }
    }
    return buildJob
}
 
List<String> getAllBuildNumbers(Job job) {
        List<String> buildNumbers = []
        (job.getBuilds()).each {
            def status = it.getBuildStatusSummary().message
            if (status.contains("stable") || status.contains("normal")) {
                buildNumbers.add(it.displayName)
            }
        }
        return buildNumbers
}
 
Job buildJob = getBuildJob()
List<String> buildNumbers = null
if (buildJob) {
  buildNumbers = getAllBuildNumbers(buildJob)
}
return buildNumbers

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 8:54:03 PM2/27/20
to jenkinsc...@googlegroups.com
Chris Fouts updated an issue
Change By: Chris Fouts
Comment:
Here's Job2's Extensible Choice Groovy script
{code:java}

import hudson.model.*

BUILD_JOB_NAME = "Utilities/Playground/Job1"

def getBuildJob() {
    def buildJob = null
    Hudson.instance.getAllItems(Job.class).each {
        if (it.fullName == BUILD_JOB_NAME) {
            buildJob = it
        }
    }
    return buildJob
}

List<String> getAllBuildNumbers(Job job) {
        List<String> buildNumbers = []
        (job.getBuilds()).each {
            def status = it.getBuildStatusSummary().message
            if (status.contains("stable") || status.contains("normal")) {
                buildNumbers.add(it.displayName)
            }
        }
        return buildNumbers
}

Job buildJob = getBuildJob()
List<String> buildNumbers = null
if (buildJob) {
  buildNumbers = getAllBuildNumbers(buildJob)
}
return buildNumbers
{code}

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 11:22:03 PM2/27/20
to jenkinsc...@googlegroups.com

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 11:22:03 PM2/27/20
to jenkinsc...@googlegroups.com

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 11:22:03 PM2/27/20
to jenkinsc...@googlegroups.com
 
Re: Job with Extensible Groovy script does NOT get latest value when triggered by another job

But Job1 has already finished running because the wait parameter in the build() call is set to false?

zilla62@gmail.com (JIRA)

unread,
Feb 27, 2020, 11:23:03 PM2/27/20
to jenkinsc...@googlegroups.com
Chris Fouts edited a comment on Bug JENKINS-61265
But Job1 has already finished running by the time Job2 runs because the {{wait}} parameter in the {{build()}} call is set to {{false}}?

devld@ikedam.jp (JIRA)

unread,
Feb 28, 2020, 1:48:02 AM2/28/20
to jenkinsc...@googlegroups.com
 

Chris Fouts Because the extensible-choice runs when a build is scheduled, not when starts.
It has nothing to do with the `wait` parameter.

Here is an issue tracker, not your support center nor stackoverflow.
Please don't reopen closed ticket without any concrete evidences, like log outputs. I believe you can verify what happen easily with removing the `if` statement.

Change By: ikedam
Status: Reopened Fixed but Unreleased
Resolution: Incomplete
Reply all
Reply to author
Forward
0 new messages