-
Improvement
-
Resolution: Fixed
-
Minor
-
Powered by SuggestiMate
It would be great if Bitbucket Build Status Notifier would support pipeline builds. There don't seem to be any way to use the Bitbucket Build Status Notifier plugin with the pipeline build that was added in Jenkins 2.0.
[JENKINS-33841] Support for pipeline builds
Perhaps some overlaps with this? https://github.com/jenkinsci/stashnotifier-plugin/issues/92
We are working with Jenkinsfile and Bitbucket. Is there already a way to update the status of pull requests and commits?
Hi all, I would like to support pipeline but currently I've no time to work on it. So if have time to invest on this feel free to fork the plugin repository and create a pull request. Anyways I'll inform here when it's done but as I said there isn't any release date for this at the moment.
I tried this plugin for the first time. I defined the OAuth in the Jenkins Global Configurations and it seems like it applied itself by default to my pipelines, which is good.
what is strange is that instead of updating the build status in BitBucket, it posts a comment on that commit saying whether it looks good or failed with a link to that build. the build status icon stays empty.
EDIT: it seems like the comments don't come from this plugin, but from the BitBucket Source plugin. and they too have an issue requesting for it to become a status update: JENKINS-33507
Support for pipeline build was added and will be available on next release.
amansilla - thanks for the update!
I updated the plugin and ran a small test in a multibranch job using the following Jenkinsfile:
node { stage 'checkout' checkout scm bitbucketStatusNotify ( buildState: 'INPROGRESS' ) } stage 'pause' input 'waiting...' stage 'complete' bitbucketStatusNotify ( buildState: 'SUCCESSFUL' )
the console output in Jenkins seems promising:
Branch indexing [Pipeline] node Running on master... [Pipeline] { [Pipeline] stage (checkout) Entering stage checkout Proceeding [Pipeline] checkout ... [Pipeline] bitbucketStatusNotify Sending build status INPROGRESS for commit 4e7eb185a08b8b5cb1775c31d26f3f05cbaa8bbc to BitBucket is done! [Pipeline] } [Pipeline] // node [Pipeline] stage (pause) Entering stage pause Proceeding [Pipeline] input waiting... Proceed or Abort Approved by Itai Sanders [Pipeline] stage (complete) Entering stage complete Proceeding [Pipeline] bitbucketStatusNotify Sending build status SUCCESSFUL for commit 4e7eb185a08b8b5cb1775c31d26f3f05cbaa8bbc to BitBucket is done! [Pipeline] End of Pipeline [Bitbucket] Notifying commit build result [Bitbucket] Build result notified Finished: SUCCESS
but when I go to the Bitbucket web interface I can't see any sign of the build status:
am I doing it wrong?
just for some more details: I tested this with both a consumer under my own account and a consumer under my team's account. both had the same result.
Hi itaisanders, can you please provide the jenkins log info during the execution of the job? Probably there we can guess what going on.
flagbit - sure:
Jul 18, 2016 11:43:00 AM INFO hudson.model.Queue maintain BuildableItem devops.tests.allsorts: pending -> buildable as the assigned executor disappeared Jul 18, 2016 11:43:46 AM WARNING org.jenkinsci.plugins.workflow.support.steps.input.InputAction loadExecutions no flow execution found for devops.tests.allsorts/notifier #7 Jul 18, 2016 11:45:33 AM INFO org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper sendBuildStatusNotification This request was sent: { "state": "INPROGRESS", "key": "[some key]", "url": "[jenkins url]/job/devops.tests.allsorts/job/notifier/8/", "name": "devops.tests.allsorts » notifier #8" } Jul 18, 2016 11:45:33 AM INFO org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper sendBuildStatusNotification This response was received: Bad Request Jul 18, 2016 11:45:59 AM INFO org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper sendBuildStatusNotification This request was sent: { "state": "SUCCESSFUL", "key": "[same key as previous request]", "url": "[jenkins url]job/devops.tests.allsorts/job/notifier/8/", "name": "devops.tests.allsorts » notifier #8" } Jul 18, 2016 11:45:59 AM INFO org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper sendBuildStatusNotification This response was received: Bad Request Jul 18, 2016 11:45:59 AM INFO org.jenkinsci.plugins.workflow.job.WorkflowRun finish devops.tests.allsorts/notifier #8 completed: SUCCESS
maybe it's the » sign that comes from the folder plugin.
as an afterthought, I decided to check this out on a job outside any foldered structure (such as in a multibranch job) and there it worked (same repo so same Jenkinsfile). moved that job into a folder, and again I get the same results as the multibranch job.
so whatever it is - it happens only when ran inside a folder.
EDIT: I took the liberty of forking the code and look into it myself. it wasn't such a huge fix. created a pull request for you.
btw, I also noticed that if I notify about an INPROGRESS status and the build fails or aborted, then there's no automatic status update in Bitbucket so it freezes on INPROGRESS.
not a show stopper, but something to think about for a future release.
Thanks for this work guys. I'm gonna test it.
Just a feedback, I'm using Jenkins 2.14 and the latest version of the plugin is 1.2.2 and not 1.3.0 in the web interface.
I'm gonna install it manually.
no problem. I am using my own locally compiled version with both my pull requests here, since I needed those fixes.
I'm sorry about the versions mixup. tbh, this is the first time I am doing an actual pull request to a Jenkins plugin and I just changed the code as needed without taking notice of the metadata that came with it.
I guess you can just commit whatever needs to be changed in the versions, or give me the pointers and I'll be glad to add them to the pull request.
Hello itaisanders
I notice that you have a status notification message in the logs
Sending build status INPROGRESS for commit 4e7eb185a08b8b5cb1775c31d26f3f05cbaa8bbc to BitBucket is done! Sending build status SUCCESSFUL for commit 4e7eb185a08b8b5cb1775c31d26f3f05cbaa8bbc to BitBucket is done!
what looks really good, but my build doesn't issue even anything close to that, I have just:
Proceeding [Pipeline] bitbucketStatusNotify [Pipeline] stage (Checkout)
and even more strange - error in the end
[Pipeline] bitbucketStatusNotify [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline java.lang.NullPointerException at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:191) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:140) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:52) at hudson.security.ACL.impersonate(ACL.java:213) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:49) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Finished: FAILURE
Can you please suggest what I might be missing? The only difference I can see between my and sample config is that I'm fetching code with credentials:
checkout([$class: 'GitSCM', branches: [[name: env.BRANCH_NAME]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'c6bcc00a-8dea-4671-bdd3-8335a959d610', url: 'git@bitbucket.xxx/xxx.git']]])
lessless: I need to see the pipeline code to be certain, but from the snippet you posted it seems like you activated the bitbucketnotifier before the checkout stage.
Proceeding [Pipeline] bitbucketStatusNotify [Pipeline] stage (Checkout)
the notifier is looking for the scm object instance, which in pipelines (unlike the freestyle jobs) is only initiated when you go through the scm checkout step, so basically you are calling for bitbucketnotifier with an uninitiated (null) scm object.
it might be best if the plugin catches this and posts a more friendly exception message. maybe I'll look into it and post another pull request later if no one gets to it.
let me know if placing the scm checkout before the bitbucketnotifier step worked or it's something else entirely.
Hi itaisanders
thank you for the tip, this is my first experience with Jenkins, so pretty frustrated atm due to the setup complexity.
I tried to `checkout scm` before setting status, but change.
Here is the script itself:
node { deleteDir() checkout scm bitbucketStatusNotify(buildState: 'INPROGRESS') sleep 10 bitbucketStatusNotify (buildState: 'SUCCESSFUL') }
and console output
Started by user lessless Replayed #2 Setting origin to git@bitbucket.org:team/proj.git Fetching origin... [Pipeline] node Running on master in /var/lib/jenkins/workspace/proj/feature%2Fadd-jenkinsfile [Pipeline] { [Pipeline] deleteDir [Pipeline] checkout Cloning the remote Git repository Cloning repository git@bitbucket.org:team/proj.git > git init /var/lib/jenkins/workspace/proj/feature%2Fadd-jenkinsfile # timeout=10 Fetching upstream changes from git@bitbucket.org:team/proj.git > git --version # timeout=10 using GIT_SSH to set credentials > git -c core.askpass=true fetch --tags --progress git@bitbucket.org:team/proj.git +refs/heads/*:refs/remotes/origin/* > git config remote.origin.url git@bitbucket.org:team/proj.git # timeout=10 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10 > git config remote.origin.url git@bitbucket.org:team/proj.git # timeout=10 Fetching upstream changes from git@bitbucket.org:team/proj.git using GIT_SSH to set credentials > git -c core.askpass=true fetch --tags --progress git@bitbucket.org:team/proj.git +refs/heads/*:refs/remotes/origin/* Checking out Revision 7911cc863d326253d1333cc899a837883dced255 (feature/add-jenkinsfile) > git config core.sparsecheckout # timeout=10 > git checkout -f 7911cc863d326253d1333cc899a837883dced255 > git rev-list 7911cc863d326253d1333cc899a837883dced255 # timeout=10 [Pipeline] bitbucketStatusNotify [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline java.lang.Exception: Credentials could not be found! at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.sendBuildStatusNotification(BitbucketBuildStatusHelper.java:262) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.notifyBuildStatus(BitbucketBuildStatusHelper.java:252) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:189) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:140) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:52) at hudson.security.ACL.impersonate(ACL.java:213) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:49) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Finished: FAILURE
lessless now you have a Credentials not Found exception. did you set them in the Jenkins Global Configurations?
if you want some general help with Jenkins maybe it will be better to move to a more general platform e.g. https://devopsengineers.slack.com/archives/jenkins-ci (once there, feel free to pm me if you'd like. although I do follow the jenkins-ci channel anyway)
Before I used generated snippet to checkout the repository,
checkout([$class: 'GitSCM', branches: [[name: 'master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'c6bcc00a-8dea-4671-bdd3-8335a959d610', url: 'git@bitbucket.org:org/proj.git']]])
but changed it to the `checkout scm` to fully reproduce your snippet.
lessless I think you are gettin mixed up.
you need to provide credentials to your repository in order to access it.
you can either:
1. provide them in the job configurations (and place the Jenkinsfile inside the scm), in which case you can simply call on 'scm checkout' to checkout the entire code. Jenkins then will use the credentials you used to access the Jenkinsfile in order to checkout that same repo.
2. provide them inside the checkout call, as you first did, in case you are writing your pipeline code inside Jenkins (so you never configured the scm in the job configurations) or in case you wish to checkout a different repo than the one you used to store the Jenkinsfile.
either way, you will still need to provide the notifier plugin with the credentials to mark the build status. you configure it inside the Jenkins Configure System (inside Manage Jenkins, not in the specific job). you will need to produce a dedicated OAuth credentials.
this and more you can find in the very good README in github: https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin
and again - this is getting much more general than the discussed issue. you should raise those questions in Slack, or if you want you can Telegram me and I wouldn't mind helping you out as far as I can.
Could we merge the pull request of itaisanders for Pipeline Multibranch Support: https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin/pull/30?
that would be great allan_burdajewicz!
btw, I didn't get to test it myself (since I am using my locally compiled merged version), but I think if you don't use the default parameters of the plugin and define your own legal parameters manually, you would work around this bug (along with the "key per job and not per build" sort-of-a-bug).
Is there a way, in a pipeline build, to override the global oauth credentials?
Code changed in jenkins
User: Jesse Glick
Path:
COMPATIBILITY.md
http://jenkins-ci.org/commit/pipeline-plugin/c84a9af380854dbafd66e265b63cd05969ad7c47
Log:
Merge pull request #439 from alexbrjo/alexbrjo-compat-update
JENKINS-32263 JENKINS-32650 JENKINS-33841 JENKINS-33310 JENKINS-26591 JENKINS-30522 Updated support status for several plugins
Compare: https://github.com/jenkinsci/pipeline-plugin/compare/23d473486c8e...c84a9af38085
I agree, we're deploying Jenkins2 using pipeline and SCM Jenkinsfile from Bitbucket and we'd like to get the build status in Bitbucket.
Currently, the Stage View visualization only displays stages status, but no information regarding the branch name is provided.
Also, bitbucket remains the place where code review is being done so having the build status is mandatory for reviewers.
Thank you.