Create a Pull request in bitbucket using Jenkins job - jenkins

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

Related

Trigger Tekton pipeline from Bitbucket webhook

In one of our project we have to integrate Bitbucket webhook with Tekton pipeline that means whenever developer commits any changes to Bitbucket repository, Tekton pipeline is triggered and will perform several steps to build.
Earlier we have used GitHub webhook with Tekton and it was working fine.
For Bitbucket webhook, we are getting below error:
failed to replace JSONPath value for param pusher-name: $(body.actor.name): name is not found".
I checked the payload coming from Bitbucket webhook and found there is no such field name.
I used bitbucket-push cluster trigger binding plugin.
Can anyone help us to resolve this issue?
You can use tekton triggers and event listener for that.
With BitBucket, the author name should be somewhere in the actor.username, actor.display_name or actor.nickname
Here's a sample bitbucket push payload
You may have other errors. Switching from one git provider to another, you may have to re-do your interceptors, triggertemplates, ...
Meanwhile, it's unclear what you refer to, by "I used butbucket-push cluster trigger ...". Where did you find this? Checking Tekton Triggers samples, there's no author.name. Sounds like your issue relates to GitHub-specific configurations.

Trigger Jenkins Job from Bitbucket on Pull Request

Hoping to gather insight from professionals. My end goal is to trigger a jenkins build whenever a bitbucket pull request happens. If anyone could give me an ELI5(explain like I am 5) answer it would be greatly appreciated. Sorry if this is the wrong format, I am new to jenkins and stackoverflow.
What I have done so far:
Created webhook in bitbucket and gave the url to my jenkins job. example: http://jenkinsURL:8080/job/boulevard-dev/generic-webhook-trigger/invoke?token=myPull_Request_Token
Pull request webhook trigger
In Jenkins, under source code management I have: Source Code Management Settings. This is currently fetching a ton of branches, failing, then building the master branch when the job starts?
For build triggers, other stackoverflow articles have pointed me to the "Generic Webhook Trigger". https://github.com/jenkinsci/generic-webhook-trigger-plugin
I am not entirely sure how this generic webhook trigger should effectively be setup? Hoping someone has experience using it and could explain what is needed.
This is what have seen referenced in other articles.Build Triggers settings Build triggers settings 2
Questions:
What does a correct setup / example of the generic webhook trigger look like?
Currently, my job triggers when a change is made to master or merged to master, how can I specify to my job that I want the bitbucket pull request branch to be built?
Also, I found this, not sure if its related to my issue or not? https://jira.atlassian.com/browse/BCLOUD-5814
As per your requirement, you can trigger a Jenkins build whenever a bitbucket pull request happens by following the below steps, in my case, it's working fine.
Step(1) - Configure Jenkins
(i) Add your bitBucket repo and branch to source code management
(ii) On build Triggers setup Poll SCM to * * * * * for run every minute to check pull request from bitBucket.
Step(2) - configure Bit Bucket Hook
(i) Go to settings and add a new hook, now setup pull request trigger as per your requirement.
Step(3) - Make a pull request and see the new job automatically triggered on Jenkins.

In Jenkins what's the differences between Remote access API and Pipeline REST API

In Jenkins, we want to get the Pipeline stages information through API, e.g. a stage is success or fail. From another answer it seems we can achieve it through Pipeline REST API Plugin.
My question is:
Can Jenkinsapi and Python-Jenkins achieve the same thing? It seems they're designed for bare metal Jenkins, instead of the Pipeline plugin, right ? If that's the case, do we have similar Python library for Pipeline plugin?
Thanks!
You have all the info to answer your own question in the documentation you linked. Just to put it together:
Jenkins has a REST API
The pipeline REST API plugin injects new endpoints in the Jenkins REST API to give you access to several pipeline info
Python-Jenkins and jenkinsapi you mentioned above are both wrappers around the Jenkins REST API to help you develop scripts/apps targeting the Jenkins API in Python. Since those modules/libs are based most probably based on the core API specification, they most probably don't provide specific methods to target the pipeline endpoints (but you can probably extend that quite easily).
If you want to stay in Jenkinsapi, get_data() defined in JenkinsBase class could be used for querying Pipeline REST API directly. Not very sure if it's recommended or not.
Following codes works for me.
from jenkinsapi.jenkins import Jenkins
import requests
requests.packages.urllib3.disable_warnings()
# GET /job/:job-name/:run-id/wfapi/describe
url = 'https://localhost/job/anyjob/10/wfapi/describe'
jenkins = Jenkins(
'https://localhost',
username='username',
password='api_token',
ssl_verify=False,
lazy=True)
print(jenkins.get_data(url))

how to trigger a jenkins multibranch job using comment a pull request with Post Webhooks for Bitbucket plugin

I'm using Post Webhooks for Bitbucket plugin to trigger pull request event.
I enabled below options:
"Pull request created"
"Pull request re-scoped"
It works find when I create a push request.
A new requirement is I wish when comment a pull request with specified info like "run this again", to trigger the jobs run, I've seen these is option:
"Pull request commented"
but I don't know how to use it.
I searched but didn't find any useful docs.
Anyone can help to give a link or an example?
I know of two solutions to this.
Solution 1
Use the webhooks that comes with Bitbucket Server. I think it was introduced in Bitbucket Server 5.4.
Use Generic Webhook Trigger Plugin in Jenkins to consume the webhook JSON. This plugin is documented on how to create filters with regexp to only trigger for some specific conditions.
Soltuion 2
Use Pull Request Notifier for Bitbucket Server plugin in Bitbucket Server. To trigger Jenkins.
Create an ordinary, no plugins needed, parameterized job in Jenkins and trigger it with the Bitbucket Server plugin.

Create a new task in Jira using Jenkinsfile

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.

Resources