Build a PR with multiple jobs?
Opened this issue · 6 comments
What feature do you want to see added?
When a pull request is opened/updated, Jenkins automatically builds it and reports its status in the Builds tab of the PR. This is great but we would like to start breaking up this job into multiple ones, as we have seen is possible on GitHub:
I was able to replicate this behaviour by running a second job and updating the build status endpoint myself. But that's extremely brittle as I can't hook into the job lifecycle as well as this plugin is doing. Is there a way this could somehow be supported out of the box?
I've seen it is possible to achieve this by having multiple Jenkinsfile inside the same monorepo. But what I would want instead is to manage those 'actions' outside the repository, so I can use them across multiple projects. The plugin would therefore need to support the use case.
Upstream changes
-
AFAIK that feature does not exist yet, but here's a draft of how it could work. Define a bitbucketBuildStatus
option and a bitbucketBuildStatus
step, that could then be used in pipelines as follows:
pipeline {
options {
// Stop Jenkins from reporting the build status of the pipeline as a whole,
// like it does by default. But if there is a syntax error in the pipeline,
// then the option won't take effect.
bitbucketBuildStatus skip: true
}
stages {
stage('Parallel') {
parallel {
stage('Java 8') {
options {
// Jenkins would report an INPROGRESS status when this stage
// starts, and SUCCESSFUL or FAILED when the stage finishes.
bitbucketBuildStatus key: 'Java 8'
}
steps {
// …
}
}
stage('Java 11') {
steps {
// Jenkins would report an INPROGRESS status when this step
// starts, and SUCCESSFUL or FAILED when the step finishes.
bitbucketBuildStatus(key: 'Java 11') {
// …
}
}
}
}
}
}
}
Would this kind of feature work for your purposes, or did you mean something different?
One problem with this draft is that Jenkins has a mutable Result for the build as a whole and also a Result for each stage. If something sets an error result for the build only, then it might be impossible to associate that with just one build status sent to Bitbucket.
Are you using Bitbucket Cloud or Bitbucket Server?
Other plugins provide steps:
Each of those plugins has documentation that shows a try-catch statement for reporting successful or failed builds.
Thanks a lot, I had no idea these steps existed! I need to experiment with them ASAP, they're certainly much easier to work with than observing the job to then POST to the endpoint myself.
We're using Bitbucket Server, by the way.
Other plugins provide steps:
* [`bitbucketStatusNotify`](https://www.jenkins.io/doc/pipeline/steps/bitbucket-build-status-notifier/#bitbucketstatusnotify-notify-a-build-status-to-bitbucket) * [`notifyBitbucket`](https://www.jenkins.io/doc/pipeline/steps/stashNotifier/#notifybitbucket-notify-bitbucket-instance)
Each of those plugins has documentation that shows a try-catch statement for reporting successful or failed builds.
bitbucketStatusNotify: does not work for my scripted pipeline. It expects 'scm' to be the actual repo that I'm trying to post status to, but it's only the case for the simplest of my pipelines.
notifyBitbucket: seems like it's for server only but I use cloud. Has anyone tried it with cloud?
It might be simpler to call Bitbucket API directly in my case. If Bitbucket Branch Source provided a step for this, it would have been helpful.
bitbucketStatusNotify: does not work for my scripted pipeline. It expects 'scm' to be the actual repo that I'm trying to post status to, but it's only the case for the simplest of my pipelines.
README shows repoSlug
and commitId
parameters. Can you use those to post to a different repository?
notifyBitbucket: seems like it's for server only but I use cloud. Has anyone tried it with cloud?
jenkinsci/stashnotifier-plugin#85 says it doesn't work with Bitbucket Cloud.
bitbucketStatusNotify: does not work for my scripted pipeline. It expects 'scm' to be the actual repo that I'm trying to post status to, but it's only the case for the simplest of my pipelines.
README shows
repoSlug
andcommitId
parameters. Can you use those to post to a different repository?
I tried, but got a seemingly unrelated error. Apparently, my 'scm' is not a 'GitSCM', but I know for sure that it is the case, so it must be some general assumption related to scripted pipelines not working here:
java.lang.Exception: Bitbucket build notifier requires a git repo or a mercurial repo as SCM at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.createBuildStatusResources(BitbucketBuildStatusHelper.java:85) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.createBuildStatusResources(BitbucketBuildStatusHelper.java:145) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.notifyBuildStatus(BitbucketBuildStatusHelper.java:235) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:202) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:148)
notifyBitbucket: seems like it's for server only but I use cloud. Has anyone tried it with cloud?
jenkinsci/stashnotifier-plugin#85 says it doesn't work with Bitbucket Cloud.
Thanks for the info.