Create a new task in Jira using Jenkinsfile - jenkins

Is there a way that I can create a new task in Jira by writing code in Jenkinsfile, I found the plugin to update the task but didn't got anything to create a new task.

You could use curl to create an issue via the JIRA REST api.
Without knowing what you've tried and what errors you've received (if any), it's kind of difficult to be more specific.

Got a plugin which actually integrates Jira with Jenkins when you are using jenkinsfile. Jira-Pipeline plugin
Usage and documentation is described in the plugin itself.

Related

Create a Pull request in bitbucket using Jenkins job

I am interested in creating a pull request on bitbucket using jenkins pipeline job based on groovy. I am creating a jenkins job which is pulling the code then doing some changes and then pushing the code to bitbucket and then I want to raise PullRequest.
Any help would be really appreciated.
Thanks
I'm looking for the same, unfortunately I only find a way to do this using the bitbucket rest apis.
It would be nice to have a plugin to do this, but I could not find it.
This is the rest api
https://docs.atlassian.com/bitbucket-server/rest/7.6.0/bitbucket-rest.html#idp291
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests
There are more details here
How to create a pull request in a Bitbucket using api 1.0

How to create a Jenkins job config.xml?

When I create a jenkins job via the API, I use a previous job's config.xml, make my modifications and then make the POST call to create the job.
My questions is, is there a way to generate this programmatically? I.e. is there a structure of a config.xml, what XML entities it should have, what values, etc so I can write a small module to generate one and send it to the jenkins API call?
I don't think there's any mandatory XML entities. Submitting an empty structure should result in a job that has default values for all settings.
What you want to do is exactly what's done by the Jenkins Job Builder. It provides a YAML-based framework for creating Job configuration XML files and submitting them to Jenkins. It's a common alternative to the Job DSL plugin. I wouldn't recommend to re-implement such a solution yourself -- handling all the plugin-specific XML configuration parts will be a nightmare.
We create our jobs using Job DSL plugin. You can try the playground http://job-dsl.herokuapp.com/.
At first, it seems that it is hard to learn, but after the first seed job, it is much better.
When we started writing our scripts we were afraid that there will not be suitable API methods for our needs. It turned out that we had one such case, which was solved using the configure block.
Get started guide here.

How to pass JOB parameters using Jenkins HTTP POST plugin

I want to pass the Build Name and the BUILD ID to the REST API using Jenkins HTTP POST plugin
how to pass the parameters to it?
I am passing:
http://localhost:55223/api/Demo?BuildName=${JOB_NAME}&BuildID=${BUILD_ID}
I am receiving an error
It looks like the Plugin does not expand environment variables, as evidenced by it's source code. As the plugin has not been updated in 2 years, I don't think there's any chance of the developer adding this anytime soon. If you are still wanting to use the plugin, you could make the changes changes necessary to expand the environment variables and then build it from source. For that, I would recommend looking at the Jenkins classes hudson.EnvVars and hudson.model.Run. More specifically, the Run method getEnvironment(TaskListener listener) and the EnvVars method expand(String s).

Jira Jenkins Integration | Issue Id

I was trying to get an SVN, Jenkins and Jira integration going. The aim being to change the status of a ticket/issue to 'Fixed' when it is referred to in an SCM comment. The process being orchestrated by Jenkins. The flow details are
developer puts in the Jira ticket number (MDP-1) on an SVN commit
message.
The build is kicked off in JenkinsJenkins (using the Jira
plugin) can figure out the Jira ticket referred to it in the SVN
commit message. It updates the Jira ticket by putting in a Jira
comment.
So far, this is working great!
Now, I also want to change
the status of the ticket to 'fixed'. I am trying to use the Jenkins
step (Progress jenkins issues by workflow action). I am unable to
access the Jira issue ID/ticket number.
I know, under the hood, the Jira plugin has access to this. Thats why it is able to put in a comment to the Jira ticket in the first case. Question is how/what variable do I use to get access to this Jira ticket# in Jenkins
I actually got this working with another Jenkins plugin (https://wiki.jenkins-ci.org/display/JENKINS/Jira-Ext+Plugin).
This captures the Jira issue_id(s) captured in the SCM commit message and exposes them in an environment variable.
Just what I was looking for!

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