Jenkins Pipeline and stash Pull Request Builder not working on PR build / update
Below is the requirement required to achieve using Jenkins Pipeline and I am a new bee in Jenkins Pipeline.
-
After completing development and pushing changes to Bitbucket, the user creates a pull request.
-
To approve a pull request, we need at least one successful Jenkins build. Thus, we would only like to get the build result of the code checked for the pull request.
-
When a pull request is created or updated, Jenkins is automatically launched for real continuous integration.
-
The build result should be returned by Bitbucket.
Used by Stash Pull Request Builder and stash Notifier for the above process, which works for a regular Freestyle project.
We need to migrate similar functionality using Jenkins pipeline, so created a jenkins job as shown below. Pipeline script to check out PR branch and trigger build below
node {
stage('Checkout') {
checkout(
[
$class: 'GitSCM',
extensions: [
[$class: 'CleanCheckout'],
],
branches: [
[name: '']
],
userRemoteConfigs:
[[
credentialsId: 'id',
url: 'repourl.git'
refspec: ('+refs/pull-requests/*/from:refs/remotes/origin/pr/*/from'),
branch: ('origin/pr/${pullRequestId}/from')
]]
])
}
stage('Build') {
sh 'make'
}
stage('notify') {
step([$class: 'StashNotifier'])
try {
// Do stuff
currentBuild.result = 'SUCCESS'
} catch(err) {
currentBuild.result = 'FAILED'
}
step([$class: 'StashNotifier'])
}
}
Although I did the above configuration, when I build / update the PR, the build does not automatically start in jenkins. I think the notification from butt to jenkins did not happen because we are specifying "origin/${pullRequestId}/from"
free style in the project. But I don't have this option to specify in a pipeline job.
Tried several alternatives as shown below.
Instead of stash Pull Request Builder, I only tried the SCM Poll project and set the cron job to run as "H/2 * * * *
". After the job is done, runs in jenkins. This means for every commit, a jenkins job is started. But Jenkins has to initiate a job when a PR is created / updated .
Also based on the question below, one answer says "In the freestyle job add a trigger to start with the pipeline as a build step" which I didn't find.
I'm missing something, of course, which might be basic and new to the jenkins pipeline.
Any hint of achieving the desired behavior?
source to share
No one has answered this question yet
See similar questions:
or similar: