I have a Jenkins job that is configured via a declarative pipeline script.
I would like to add a comment to the related Jira issue when a build passes / fails.
The plugins that are available don't give very good documentation with regards to using them with a pipeline. I have tried to use the "Jira Plugin" as it is explained in this answer:
Updating Jira tickets from 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 via the pipeline?
Using jira-steps-plugin:
pipeline {
stages {
stage('jira') {
steps {
comment_issues()
}
}
}
}
void comment_issues() {
def issue_pattern = "TEST-\\d+"
// Find all relevant commit ids
currentBuild.changeSets.each {changeSet ->
changeSet.each { commit ->
String msg = commit.getMsg()
msg.findAll(issue_pattern).each {
// Actually post a comment
id -> jiraAddComment idOrKey: id, comment: 'Hi there!'
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With