Trigger jenkins from JIRA-workflow - jenkins

we have jenkins CICD automated pipelines working great. we also trigger it via REST API with build Parameters.
Now, we have JIRA dashboard having custom workflow created where developers moves or changes queue of issues/stories to "ReadyForDeployment" once development is completed.
Now here, once developer moves queue to "ReadyForDeployment" :-
JIRA should prompt for 3 fields (ENV, PACKAGE_NAME_APP and
PACKAGE_NAME_DB) those will be placed in jenkins URL like
blahblahblah/buildWithParameters?ENV=${ENV}& PACKAGE_NAME_APP=${PACKAGE_NAME_APP}&PACKAGE_NAME_DB=${PACKAGE_NAME_DB}
Basically upon queue change,webhook should be triggered whcih
will take input/parameters from JIRA itself.
Please let me know your thoughts on this.

It depends on your requirement whether its correct or not. But it can be possible to trigger jenkins from Jira useing Jira-weebhook and passing the parameters.
https://developer.atlassian.com/jiradev/jira-apis/webhooks

Related

Jenkins JIRA Trigger Plugin Only Triggers 1 Job

I've setup a webhook trigger from JIRA to trigger a Jenkins job.
This works fine for 1 particular Jenkins job, I can see the JIRA content coming in and the test Jenkins job runs fine.
However I can't get any other jobs to run from the webhook. Even if I copy the job that works correctly, that doesn't trigger either and I can't see anyway of debugging the issue.
Can anyone help shed some light on my issue please?
Thanks
I would recommend you to use the Generic Webhook Trigger plugin, you can add a Token that will help you specify which job you need to run for a specific webhook.
https://plugins.jenkins.io/generic-webhook-trigger/

Updating JIRA issues from gitlab pipeline

I want to move an issue to the deployed stage (transition) when the gitlab pipeline of a merge request has finished. Is that even possible?
My Idea so far:
The pipeline is related to that specific issue by both the branch name (see 1.) of the merge request and also the message of that merge request like so "Finish PV-1234".
I can parse the issue key from the branch name.
I can call a server to run a script making the Jira api call.
If you directly want to close the issu, look into the gitlab jira integration docs - therefore you have to add a description to your MR, to tell the integration to close the issue, as soon as the MR was merged.
If you want more control, write yourself a simple script, that first gets the ids of the available transition (You can get them via /rest/api/3/issue/{issueIdOrKey}/transitions see here) and after that posts the transition you want (You can do that by posting on the same endpoint, as the get command mentioned before see here).
Sad that the jira integration doesn't provide more issue-movement than jsut closing issues...

Monitoring external event job progress using Jenkins

How can I make an external job appear on a Jenkins dashboard more like a native Jenkins job, specifically including a progress 'bar'?
I've come across https://plugins.jenkins.io/external-monitor-job but this only appears to provide a way to say
My jobs has finished with this console output and this result code.
I would also like to see things such as current progress. Or to put it another way, I'd like my external job to be able to appear on something like https://kj187.github.io/dashing-jenkins_job/ in a similar manner to a native Jenkins job.
So is it possible to push more data than the external-monitor-job suggests?
Create a free style job and monitor the external process (print logs etc.) in the free style job - read the logs till logical conclusion in the freestyle job
What about pipeline view plugin?
Steps will be:
v1 (manual way)
create a job called monitoring_external_process inside pipeline view. This job performs a kind of ping looking the end of your process.
start your external process in a separate way.
go to jenkins monitoring_external_process job and press build.
a progress bar will be showed until the end of your external process.
v2 (automatic way)
create a job called monitoring_external_process inside pipeline view. This job performs a kind of ping looking the end of your process.
configure a webhook trigger or remote build for this job. This enable a public url to invoke the jenkins job. (See link reference #2)
configure your external process to perform an htttp request to the public url.
start your external process in a separate way.
Automatically your job will be started and progress bar will be showed until the end of your external process.
References:
(1) https://code-maven.com/jenkins-pipeline-hello-world
(2) https://jrichardsz.github.io/devops/devops-with-git-and-jenkins-using-webhooks

How to post jenkins job result in jira?

I am running jobs in Jenkins. I want to share the Jenkins job result in Jira. I have tried various plugins but failed to achieve my objective.
https://wiki.jenkins-ci.org/display/JENKINS/JIRA+Plugin
If you also want to use this feature, you need to supply a valid user id/password. If you need the comment only to be visible to a certain JIRA group, e.g. Software Development, enter the groupname.
Now you also need to configure jobs. I figured you might not always have write access to the JIRA (say you have a Jenkins build for one of the Apache commons project that you depend on), so that's why this is optional.

How to trigger a Jenkins job from a status change in Jira

I have been looking for a while now for a way to trigger a Jenkins job from the status or a ticket/story in Jira changing status. To give a more detailed example when my team moves a ticket to the 'ready for test' column we would like to be able to trigger a sanity test pack in Jenkins, the ideal situation would then be that we are able to post the results (generated as a html) as a comment on the ticket within Jira. Failing that we would like to be able to publish the results as simply pass/fail.
I have recently been looking at the Jenkins Jira plugin but this does not seem to have the functionality to work both ways, in other words it can post results after a job has run but you cannot trigger the job from a change of status in Jira. Is there any such plugin available or is it something that we will need to create ourselves?
Cheers in advance
So, basicly there are webhooks in jira (https://developer.atlassian.com/jiradev/jira-architecture/webhooks). With it you can configure it to trigger specific url on issue status change. The specific url should be jenkins API, for example for triggering a build you should call an external url like (if you are building with parameters): http://server/job/myjob/buildWithParameters?token=TOKEN&PARAMETER=Value
Some more info https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
I have written a Jenkins plugin that supports JIRA status change trigger: jira-trigger-plugin.
This plugin also injects an environment variable of JIRA_ISSUE_KEY, so you can utilise this information to publish your result back to JIRA e.g. using REST API.
Please follow as mentioned below:
GIT:
You can set the web hooks for git/ bitbucket /stash on commit which inturn should change the state of task in JIRA.
JIRA:
Once you in JIRA. define the workflow for your task.
In this particular workflow you can set a post-function where the web hook should be configured. In this configuration of webhook in events define JQL as below:
status CHANGED FROM "To Do" TO "ready to test".
In the same mention the job that needs to be fired in the URL section.
You can look through webhooks in Jira :
https://support.atlassian.com/jira-cloud-administration/docs/manage-webhooks/
You also need to add the Generic Webhook Trigger plugin to your Jenkins :
https://plugins.jenkins.io/generic-webhook-trigger/
You can find here an example on how to use the Generic Webhook Trigger plugin with Bitbucket Github and Gitlab. https://github.com/jenkinsci/generic-webhook-trigger-plugin/tree/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd
It involved multiple steps
If you are using Git/Stash/BitBucket (which i implemented),
You can simply
configure the commit hooks in your Stash/Bitbucket
Attach events to your JIRA workflow
Jenkins JOB - post build events - configure Notify
Stash plugin Set the Poll SCM
That's it

Resources