What is it.badgeActions

43 views
Skip to first unread message

Matt Graham

unread,
Mar 4, 2021, 12:22:08 AM3/4/21
to Jenkins Users

Hi All

Im new to jenkins and we have a Groovy script that get successful build information. Now, we have this bit that iterates over it.badgeActions. Suddenly Im seeing that badgeAction empty. When I check some old builds, it has an array of

[hudson.plugins.git.GitTagAction@455c11af]

If I remove the it.badgeActions.each  loop, I see the build numbers. Firstly, what is is the "it" in def build = it and what the hell is a badgeAction and should I be concerned its empty?

Thanks for any help


def job = jenkins.model.Jenkins.instance.getItemByFullName("${imageTag}/release%2F2.177.0")
job.builds.each {
def build = it

  println "${it.getResult()}"
if (it.getResult().toString().equals("SUCCESS")) {
  println "${it.badgeActions}"
    it.badgeActions.each {
      println "${build.displayName}"
            builds.add(build.displayName[0..-1])
    }
    
  }
}

builds.unique();

Mark Waite

unread,
Mar 4, 2021, 12:41:26 AM3/4/21
to Jenkins Users
On Wednesday, March 3, 2021 at 10:22:08 PM UTC-7 Matt  wrote:

Hi All

Im new to jenkins and we have a Groovy script that get successful build information. Now, we have this bit that iterates over it.badgeActions. Suddenly Im seeing that badgeAction empty. When I check some old builds, it has an array of

[hudson.plugins.git.GitTagAction@455c11af]


Those were probably builds that were run before you installed git plugin 4.5.0.  The git tag action was removed by default from Jenkins jobs created with git plugin 4.5.0 and later.  Refer to the git plugin documentation for the explanation why the git tag action is not useful in almost all cases with Jenkins.

As a quick test, you can enable the "Add git tag actions to jobs" checkbox in the Jenkins global configuration and run your job again.  That should assign the GitTagAction to the new build.

I believe "it" in that groovy loop is used to represent each of the builds in the job, one at a time, while the each loop is iterating over each of the builds.

That looks like the code used in https://stackoverflow.com/questions/27361480/how-can-i-list-successful-jenkins-builds-using-a-groovy-script-in-a-deploy-job .  You may want to try the simplification that is offered in comment 3 where it suggests

job.builds.findAll{ it.result.toString()=='SUCCESS' && it.badgeActions }.collect{ it.displayName[1..-1] }

Mark Waite

Matt Graham

unread,
Mar 4, 2021, 3:23:57 AM3/4/21
to Jenkins Users
Thank you Mark.

I appreciate that. I started to suspect it was something like a plugin as we had just updated them and I did check another job. I'll look over that link you sent as well. Maybe time to simplify it.
Reply all
Reply to author
Forward
0 new messages