Integrating jira issue creator in jenkins pipeline

828 views
Skip to first unread message

touseef

unread,
Nov 10, 2019, 11:31:03 PM11/10/19
to Jenkins Users

I want to Create Jira Issue on Build Failure through Jenkins pipeline.I am able to achive this help in freestyle projects.

Can anyone help me in integrating the create jira issue in jira automatically via pipeline syntax when jenkins build fails.



Anish Choudhary

unread,
Nov 11, 2019, 10:57:33 AM11/11/19
to jenkins...@googlegroups.com
Hi Touseef,

As excepted JIRA issue can be created in pipeline projects, using Jenkinsfile (assuming you are known of Jenkinsfile [pipeline steps written in groovy language]). Anyway we can use the following syntax (code Snippet) to implement it :
//--------------------------------------------------------------------------------------------------
pipeline {
     agent any
    stages {
        stage('build') {
            steps {
                echo "build steps"
            }
        }
stage('testing') { steps { echo "unit testing" } }
}
}


post { success { emailext ( to: 'bangarw...@gmail.com', mimeType: 'text/html', subject: "*************** As excepted***********", body: "************** As excepted **************" ) } failure { emailext ( to: 'bangarw...@gmail.com', mimeType: 'text/html', subject: "*************** As excepted***********", body: "************** As excepted **************" )
create_newjira_issue()
} }

void create_newjira_issue() { node { stage('JIRA') { def NewJiraIssue = [fields: [project: [key: 'PROJETC_NAME : can be taken from JIRA website'], summary: 'Build Failed : Summary.', description: 'Description of JIRA ticket ', issuetype: [id: 'PROJECT ID : can get using JIRA API']]] response = jiraNewIssue issue: NewJiraIssue, site: 'THAT CAN BE SET IN JENKINS CONFIGURATION OR CAN DIRECTLY WRITE HERE' echo response.successful.toString() echo response.data.toString() } } }
//--------------------------------------------------------------------------------------------------

Note : To get the JIRA fields you should have admin access of JIRA else get above information from JIRA admin.

Regards,
Anish Choudhary


On Mon, Nov 11, 2019 at 10:01 AM touseef <tousee...@gmail.com> wrote:

I want to Create Jira Issue on Build Failure through Jenkins pipeline.I am able to achive this help in freestyle projects.

Can anyone help me in integrating the create jira issue in jira automatically via pipeline syntax when jenkins build fails.



--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e3fbcd13-9e9d-4eab-b3b9-222e9864d6b6%40googlegroups.com.

touseef

unread,
Nov 12, 2019, 12:36:59 AM11/12/19
to Jenkins Users
Thanks Anish for the reply.

while runing the script provided ,i ended up in

Error when executing always post condition:
java.lang.NoSuchMethodError: No such DSL method 'jiraNewIssue' found among steps 
i am new bee.I tried debugging but could not trace back


pipeline {
     agent any
    stages {
        stage('build') {
            steps {
                echo "build steps"
            }
        }
        stage('testing') {
            steps {
                echo "unit testing"
            }
        }
    }


  post {
        always {
            echo 'I will always say Hello again!'
            create_newjira_issue()
              script {
                        def mailRecipients = 'x...@gmail.com'
                        emailext body: '${SCRIPT, template="email.groovy"}',
                        mimeType: 'text/html',
                        subject: "[Jenkins] ",
                        to: "${mailRecipients}",
                        replyTo: "${mailRecipients}"
                        
                            }
            
        }
    }
}
void create_newjira_issue() {
    node {
      stage('JIRA') {
        def NewJiraIssue = [fields: [project: [key: 'JIT'],
            summary: 'Build Failed : Summary.',
            description: 'Description of JIRA ticket ',
            issuetype: [id: '3']]]

    response = jiraNewIssue issue: NewJiraIssue, site: 'THAT CAN BE SET IN JENKINS CONFIGURATION OR CAN DIRECTLY WRITE HERE'

    echo response.successful.toString()
    echo response.data.toString()
    }
  }
}


On Monday, 11 November 2019 21:27:33 UTC+5:30, Anish Choudhary wrote:
Hi Touseef,

As excepted JIRA issue can be created in pipeline projects, using Jenkinsfile (assuming you are known of Jenkinsfile [pipeline steps written in groovy language]). Anyway we can use the following syntax (code Snippet) to implement it :
//--------------------------------------------------------------------------------------------------
pipeline {
     agent any
    stages {
        stage('build') {
            steps {
                echo "build steps"
            }
        }
stage('testing') { steps { echo "unit testing" } }
}
}


post { success { emailext (
                mimeType: 'text/html',
                subject: "*************** As excepted***********",
                body: "************** As excepted **************"
            )
        }
        failure {
            emailext (
                mimeType: 'text/html',
                subject: "*************** As excepted***********",
                body: "************** As excepted **************"
            )
create_newjira_issue()
} }

void create_newjira_issue() { node { stage('JIRA') { def NewJiraIssue = [fields: [project: [key: 'PROJETC_NAME : can be taken from JIRA website'], summary: 'Build Failed : Summary.', description: 'Description of JIRA ticket ', issuetype: [id: 'PROJECT ID : can get using JIRA API']]] response = jiraNewIssue issue: NewJiraIssue, site: 'THAT CAN BE SET IN JENKINS CONFIGURATION OR CAN DIRECTLY WRITE HERE' echo response.successful.toString() echo response.data.toString() } } }
//--------------------------------------------------------------------------------------------------

Note : To get the JIRA fields you should have admin access of JIRA else get above information from JIRA admin.

Regards,
Anish Choudhary


On Mon, Nov 11, 2019 at 10:01 AM touseef <tousee...@gmail.com> wrote:

I want to Create Jira Issue on Build Failure through Jenkins pipeline.I am able to achive this help in freestyle projects.

Can anyone help me in integrating the create jira issue in jira automatically via pipeline syntax when jenkins build fails.



--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

Anish Choudhary

unread,
Nov 12, 2019, 2:10:25 AM11/12/19
to jenkins...@googlegroups.com
Error when executing always post condition:
java.lang.NoSuchMethodError: No such DSL method 'jiraNewIssue' found among steps 
 jiraNewIssue is defined under JIRA plugin, please make sure you have installed the right JIRA plugin @ your's Jenkins setup.

Regards,
Anish Choudhary


To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/54397b05-f2b0-415a-8b02-34a996425c84%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages