Home > Enterprise >  In Jenkins pipeline how to use plugin Jira-steps to get specific version id?
In Jenkins pipeline how to use plugin Jira-steps to get specific version id?

Time:12-02

Good day, my problem is that i´m not fluent in groovy. And i need to get from the pipeline the version in Jira that i want. The problem is, i only have the name of the version, and in the plugin it is needed the id of the version to updated.

This is the plugin:

https://jenkinsci.github.io/jira-steps-plugin/steps/

https://www.jenkins.io/doc/pipeline/steps/jira-steps/

I have done it with curl throught the API in a sh step but would like to try this plugin

I´m using jiraGetProjectVersions to call all the versions then from the name extract the id. But i dont know how to do it or how to iterate to get the id that i want. Currently i can get a list of all the versions, but how to navigate the map to get the id?

/*jiraGetProjectVersions: JIRA Steps: Get Project Versions

    idOrKey : String
    auditLog : boolean (optional)
    failOnError : boolean (optional)
    queryParams (optional)
        Type: java.util.Map<java.lang.String, java.lang.String>
    site : String (optional)*/


def version = jiraGetProjectVersions idOrKey: 'PROJECT'
echo version.data.toString()

//Output:

[["self": "https://your-domain.atlassian.net/rest/api/3/version/10000", "id": "10000", "description": "An excellent version0", "name": "New Version 0", "archived": false, "released": true, "releaseDate": "2010-07-06", "overdue": true, "userReleaseDate": "6/Jul/2010", "projectId": 10000], 
[ "self": "https://your-domain.atlassian.net/rest/api/3/version/10001", "id": "10001", "description": "An excellent version1", "name": "New Version 1", "archived": false, "released": true, "releaseDate": "2010-07-07", "overdue": true, "userReleaseDate": "7/Jul/2010", "projectId": 10000],
[ "self": "https://your-domain.atlassian.net/rest/api/3/version/10002", "id": "10002", "description": "An excellent version2", "name": "New Version 2", "archived": false, "released": true, "releaseDate": "2010-07-08", "overdue": true, "userReleaseDate": "8/Jul/2010", "projectId": 10000],
[ "self": "https://your-domain.atlassian.net/rest/api/3/version/10003", "id": "10003", "description": "An excellent version3", "name": "New Version 3", "archived": false, "released": true, "releaseDate": "2010-07-09", "overdue": true, "userReleaseDate": "9/Jul/2010", "projectId": 10000]]

CodePudding user response:

You should be able to do the below.

version.data.each{ val ->
  println val.id
}

For a specific version id just do:

version.data.each{ val ->
  if (val.name == "New Version 1") {
    println val.id
  }
}

//Output:
10001
  • Related