How to add a comment to Jira issue from Jenkins project?

I have a Jenkins job that is configured through a declarative pipeline script.

I would like to add a comment to the Jira related issue when the assembly fails / fails.

The plugins that are available do not provide very good documentation regarding their use with the pipeline. I tried using "Jira Plugin" as explained in this answer:

Updating Jira tickets from a Jenkins workflow (jenkinsfile)

step([$class: 'hudson.plugins.jira.JiraIssueUpdater', 
    issueSelector: [$class: 'hudson.plugins.jira.selector.DefaultIssueSelector'], 
    scm: [$class: 'GitSCM', branches: [[name: '*/develop']], 
        userRemoteConfigs: [[url: 'https://github.com/something.git']]]])

But I get this error:

java.lang.IllegalArgumentException: Unsupported run type org.jenkinsci.plugins.workflow.job.WorkflowRun
at hudson.plugins.jira.JiraIssueUpdater.perform(JiraIssueUpdater.java:69)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:78)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:65)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
at hudson.security.ACL.impersonate(ACL.java:260)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Has anyone successfully done this through a pipeline?

+4
source share
1 answer

Using Jenkins Jira plugin :

stage('jira') {
    steps {
        script {
            // Get the list of solved issues and loop over it
            jiraIssueSelector(issueSelector: [$class: 'DefaultIssueSelector'])
            .each {
                // jiraComment is provided by Jira-plugin
                id -> jiraComment(issueKey: id,
                    body: "This issue was mentioned in [${env.BUILD_NUMBER}|${currentBuild.absoluteUrl}]"
                )
            }
        }
    }
}

:

  • , script {}, .
  • , .
+1

Source: https://habr.com/ru/post/1677252/


All Articles