首页 > 解决方案 > 如何使用 Jenkins 声明性脚本获取 JIRA 票号

问题描述

如何使用 Jenkins Pipeline 脚本获取 JIRA 票号示例:

CICD-34

以下命令提供了有关票证的完整信息,但我们如何仅获取 ID 并将其存储在变量中?

def issue = jiraJqlSearch jql: 'PROJECT = CICD AND description~"New JIRA Created from Jenkins through Declarative PL script"', site: 'MyLocalJira'”<br> echo issue.data.toString()

标签: jenkins-pipelinejira

解决方案


我有同样的问题并找到解决方案。我和你分享我的答案:)

def testExecutionSearch = jiraJqlSearch jql: "project=${project} and issuetype = 'Test Execution' and summary  ~ '${summary}'", site: 'myjira', failOnError: true

if (testExecutionSearch != null){
    //Get all issues
    def issues = testExecutionSearch.data.issues
    //Get the key of the first result
    def key = issues[0].key
}

在这里,我采用 jql 搜索的第一个元素(def key = issues[0].key),但你可以选择你想要的:)


推荐阅读