Howto prevent jenkins updating build status in bitbucket - jenkins

I have got a jenkins pipline which is triggered by any new commit to my development repository at bitbucket.
The pipeline starts multiple instances of a downstream pipeline (slave) with different parameters which is checking out my repo und building the source. The pipeline script for the BUILD pipeline is also from the SCM.
After building each configuration, the result ist reported back to the bitbucket repo by the bitbucket server notifier plugin.
So I got the following reports at bitbucket for each commit:
master pipline build pipline (from SCM) bitbucket status
=============== ========================= ===================
commit ->
start build 1 ------> building (config A) ------> 1. "build pipline running"
2. "build pipline done"
<<-------------------------------------------------------------------
posting "build done conf A" to bitbucket ---------------------->> "build done conf A"
start build 2 ------> building (config B) ------> 1. "build pipline running"
2. "build pipline done"
<<-------------------------------------------------------------------
posting "build done conf B" to bitbucket ---------------------->> "build done conf B"
So at the end I got 3 results at bitbucket:
"build pipeline done"
"build done conf A"
"build done conf B"
But I dont want to have the status of the "build (slave) pipeline" at bitbucket!
So how can I prevent jenkins from propagating the build status of "build pipeline" to the bitbucket server?
I suppose the status is propagated because of the "Pipline script from SCM" option.
Greetings!

Related

How to change "default" Jenkins build status label on GitHub?

What do I have:
Jenkins job (Freestyle Project). Job trigger is GitHub Pull Request Builder
GitHub repository
Webhook to trigger the Jenkins job
What do I want: change "default" label from the screenshot below to something more specific, lets say, "Codestyle"
, so the text will be "Codestyle - Build finished."
What have I tried: adding GitHub commit status
It resulted in two build statuses:
Found a workaround (reference):
GitHub Pull Request Builder -> Application Setup:
Job -> Build Triggers -> Trigger Setup
Result:
To keep build statuses, I removed --none-- from "Commit Status Build Triggered" and "Commit Status Build Started" fields.
Build triggers ==> Trigger Setup ==> Commit Status Context ==> Here specify the name and it will appear on the github.

Jenkins simple pipeline not triggered by github push

I have created a jenkins pipeline job called "pipelinejob" with the below script:
pipeline {
agent any
stages {
stage ('Setup'){
steps{
//echo "${BRANCH_NAME}"
echo "${env.BRANCH_NAME}"
//echo "${GIT_BRANCH}"
echo "${env.GIT_BRANCH}"
}
}
}
}
Under General, I have selected "GitHub project" and inserted my company's github in the form:
https://github.mycompany.com/MYPROJECTNAME/MY_REPOSITORY_NAME/
Under Build Triggers, i have checked "GitHub hook trigger for GITScm polling
I have created a simple job called "simplejob" with same configuration as 1) and 2)
In my company's Github, i have created a webhook like "jenkins_url/jenkins/github-webhook/"
I commit a change in "mybranch" in "MY_REPOSITORY_NAME"
My simple job "simplejob" is triggered and built successfully
My pipeline job "pipelinejob" is not triggered
In Jenkins log i see the below:
Sep 12, 2019 2:42:45 PM INFO org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber$1 run
Poked simplejob
Nothing regarding my "pipelinejob".
Could you please point me to the right directions as to what to check next?
P.S. I have manually executed my "pipelinejob" successfully
I wasted two days of work on this, as none of the previous solutions worked for me. :-(
Eventually I found the solution on another forum:
The problem is that if you use a Jenkinsfile that is stored in GitHub, along with your project sources, then this trigger must be configured in the Jenkinsfile itself, not in the Jenkins or project configuration.
So add a triggers {} block like this to your Jenkinsfile:
pipeline {
agent any
triggers {
githubPush()
}
stages {
...
}
}
Then...
Push your Jenkinsfile into GitHub
Run one build manually, to let Jenkins know about your will to use this trigger.
You'll notice that the "GitHub hook trigger for GITScm polling" checkbox will be checked at last!
Restart Jenkins.
The next push should trigger an automated build at last!
On the left side-pane of your pipeline job, click GitHub Hook log. If it says 'Polling has not run yet', you will need to manually trigger the pipeline job once before Jenkins registers it to poke on receiving hooks.
Henceforth, the job should automatically trigger on GitHub push events.
I found an answer to this question with scripted pipeline file. We need to declare the Github push event trigger in Jenkins file as follows.
properties([pipelineTriggers([githubPush()])])
node {
git url: 'https://github.com/sebin-vincent/Treasure_Hunt.git',branch: 'master'
stage ('Compile Stage') {
echo "compiling"
echo "compilation completed"
}
stage ('Testing Stage') {
echo "testing completed"
echo "testing completed"
}
stage("Deploy") {
echo "deployment completed"
}
}
}
The declaration should be in the first line.
git url: The URL on which pipeline should be triggered.
branch: The branch on which pipeline should be triggered. When you specify the branch as master and make changes to other branches like develop or QA, that won't trigger the pipeline.
Hope this could help someone who comes here for an answer for the same problem with Jenkins scripted pipeline :-(.
The thing is whenever you create a pipeline job for git push which is to be triggered by github-webhook, first you need to build the pipeline job manually for one time. If it builds successfully, then Jenkins registers it to poke on receiving hooks. And from the next git push, your pipeline job will trigger automatically.
Note: Also make sure that the pipeline job built manually for the first time should be built successfully, otherwise Jenkins will not poke it. If it fails to build, you can never trigger the job again.

Jenkins "build error" for the same build command which builds "success build" simultaneously

I am using Jenkins for CI/CD on the AWS server. I have configured the job which includes Github private repo.
"Build Trigger->Poll SCM-> * * * * *" configuration is using for Build Triggering.
"Build Environment->Delete workspace before build starts" for the Build environment
"Build-> Execute Shell" (the script is below)
pm2 stop <*pm2 id*>
npm install
npm run build
pm2 serve build <*server port*>
The thing is this configuration built successfully and I could see the output as expected.
And the problem is the same configuration build failed for very next of success build.
If I wait a few minutes and build the job again it "build success"
So my query is, should I have to wait a certain time duration after a successful build or something else?

Branch Indexing in jenkins multibranch pipeline triggers extra build, which is already built by poll SCM

I have a multibranch pipeline.
I have configured Trigger in jenkinsFile properties:
pipelineTriggers([pollSCM('H/2 * * * *')])])
The multibranch pipeline is configured to "scan Multibranch Pipeline Triggers" periodically.
Expected behavior: Trigger builds only on build triggers configured through jenkinsFile
Actual: It triggers build on Poll SCM and also on "re-indexing" for the same commit.
We are using
Jenkins: 2.107.1
git plugin: 3.8.0
Pipeline multibranch: 2.17
I guess we can not stop the build trigger from scanning. But our build should be able to identify and stop the additional build.
// execute this before anything else, including requesting any time on an agent
if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
print "INFO: Build skipped due to trigger being Branch Indexing"
currentBuild.result = 'ABORTED' // optional, gives a better hint to the user that it's been skipped, rather than the default which shows it's successful
return
}
Source: https://www.jvt.me/posts/2020/02/23/jenkins-multibranch-skip-branch-index/

how to configure job in jekins if first project is build successful then trigger another project and so on with "Multi-configuration project" job

I want to trigger project in jekins if first project is build successful then trigger another project and so on.. how can do it. I hava project1 , project2, and project3, project4, project5 so on. here I am configuring "Multi-configuration project" job.
for exp:- project1->success then trigger project2->success then trigger project3
if any stage failed then doesn't trigger other project.This is "Multi-configuration project" job, because this single job, I am trigger on multiple slaves remotely.
A simple way to do this would be to define this build pipeline using the Pipeline plugin.
This pipeline script should give you the desired behaviour:
build job: 'project1'
build job: 'project2'
build job: 'project3'
build job: 'project4'
build job: 'project5'
i.e. A build of each job will be started in sequence; if any one of them fails, then the subsequent jobs will not be started.
Even with "Multi-configuration project" you should be able to set a post-build action "Trigger parameterized build on other projects". Then you can specify condition which will define when this project should be build, and add parameters, including "build on the same node".

Resources