Can't configure Scan Multibranch Pipeline Triggers in Jenkins Pipeline - jenkins

In our Jenkins pipeline setup, I am only able to view configuration for Repo and Branch level. Scan Multibranch Pipeline Triggers is set for 1 day. I think because of this setting Scan periodically starts rebuilding all the BitBucket pull requests when it sees changes on the source branch. I want to disable this auto-building somehow, configuration settings are not an option. Even though I am an administrator on Jenkins with full power, I get the following message when I view configuration "username missing the Job/Configure permission" . Is there any way to fix this setting or something I can do in the Jenkinsfile to prevent building PRs every time there is a new MultiBranch Pipeline scan.

Related

BitBucket webhook triggers *all* Jenkins multibranch pipelines, even those who have that setting disabled

Context: We have a Jenkins 2.361.3 server and a local Bitbucket server with webhooks (on Push) that trigger multibranch pipeline jobs (declarative jenkinsfile mode) on Jenkins for every repo push. This works fine when we have a single multibranch pipeline job on Jenkins: the build is triggered for the correct branch.
New scenario: We want a second 'nightly' multibranch pipeline job on the same Jenkins server for the same Bitbucket repo, which we want to trigger on a fixed time every day for every branch that exists at that time. It should not trigger for repo pushes.
Actions taken: We created a second multibranch pipeline job, similar to the first one but now with a cron trigger in the jenkinsfile and this setting disabled: "Build when a change is pushed to BitBucket":
This setting is still enabled for the initial job.
Expectations:
On a repo push, only the initial job is triggered. The nightly job does nothing.
When the cron time hits, the night job is triggered.
Actual:
On a repo push, both jobs are triggered. (also after Jenkins restart)
Additionally, the cron trigger works as expected.
Question: How to configure this system so that a repo push only triggers the initial job and not the nightly job?
It looks like the combination of BitBucket plugin (v223) and Multibranch Pipeline plugin (v716) does not adhere to the "Build when a change is pushed to BitBucket" setting.
Experiments performed:
Disabling the "Build when a change is pushed to BitBucket" setting for both jobs (and restarting Jenkins) --> both jobs are still triggered by a repo push
Remove the webhook from BitBucket and configure 'polling SCM' for both jobs --> this works but polling feels suboptimal and adds performance hits to the server.
We solved it using the “Suppress automatic SCM triggering” property in the ‘Branch Sources’ section of the Jenkins configure page for the job, as explained here.
The ‘Scan multibranch pipeline trigger’ setting only controls the scans (even though the text says ‘build’), and this will cause a trigger. The Suppress property lets a certain job ignore a webhook or scan trigger. And then the job is only triggered by its cron-trigger, which is what we wanted.

Unable to understand scm sync pop up message on Jenkins

We are using Multi-branch pipeline Jenkins jobs with SCM sync
Configuration plugin installed. Since few days a warning is being popping up at the end of Jenkins console. Can anyone explain what it is trying to inform us.
Error: Delete jobs/wbe-middle-layer-inbound/branches/feature-LMS-4271-Release2.83lj1k
Here we in git we don't have branch feature-LMS-4271-Release2.83lj1k under wbe-middle-layer-inbound repo but having feature-LMS-4271-Release2.
Periodically the multi-branch pipeline job just scan your repo to determine if any of it's branches meet the criteria for a pipeline to be created for them. It also tells you the pipelines it deletes because the branch that it was matched to is no longer there. Could that be what you're seeing?

Jenkins multibranch pipeline jobs not detects changes

Dear Jenkins maintainers,
I have a CI system where hosted BitBucket server able to notify the Multibranch Pipeline about the Pull Request changes.
When I click "Scan Multibranch Pipeline Now" everything works as expected. The scan searches for BitBucket PRs and only finds the ones which contain the Jenkinsfile.
Those ones trigger a job immediately.
Checking PR-10 from PROJECT/repo and branch my_branch
Changes detected: PR-10 ({old_hash} → {new_hash})
Scheduled build for branch: PR-10
However, If Jenkins was notified by webhook, the job is not triggered.
I see in the "Multibranch Pipeline Events" that the notification has arrived, and it is checking the existing PRs. Actually, the checks find no changes on branches, which happens with "Scan Multibranch Pipeline Now".
Do I miss something here?
Why the notification event does not behave the same as the scan and triggers job corresponding to the changed branch (PR)?
I appreciate any answer and I can share deeper details on request.

Trigger Jenkins Multibranch Pipeline Scan from another job

Is it possible to trigger Scan Multibranch Pipeline Now action for a Jenkins Multibranch Pipeline from another Job? I have certain issues integrating my old version of Gitlab with Pipeline Jobs in Jenkins and came upon such a workaround.
Alternatively, would it be possible to trigger Scan Multibranch Pipeline Now with a notifyCommit web hook?
The purpose of this would be to Scan Multibranch Pipeline whenever a change occurs in the Git repo, so that new branches are detected after such a change.
Another purpose, which I am unable to achieve otherwise (except for periodic polling per branch which is plain evil to me), is to trigger build of branches affected by given changeset. I use old GitLab (7.8) which does not work with the ordinary Gitlab plugin and the Gitlab Hook plugin does not work with pipeline jobs, so my workaround would be to have an non-Pipeline Job to be triggered by Gitlab Hook plugin and this job would in turn trigger Scan Multibranch Pipeline.
Turned out that simple notifyCommit web hook did the job

How to trigger Multibranch Pipeline build with github webhook

In freestyle job there is an option named "GitHub hook trigger for GITScm polling" on stage Build Trigger.
screen capture here:
.
Together with webhook in gitlab config "http://myjenkins/gitlab/notify_commit" it works fine, meaning that the build will be triggered automatically when something is pushed to the repository.
But why in Multibranch Pipeline there is only one option named "Periodically if not otherwise run"? Is there some plug-in not installed? How to trigger Multibranch Pipeline build with github webhook like freestyle job
This page described how to configure pipeline-as-code on multibranch workflow in jenkins.
This is the quote from the description inside:
The Workflow Multibranch feature (provided by the workflow plugin) provides the following key abilities:
Automatic Workflow (job) creation in Jenkins per new branch in the
repo (assuming webhooks are registered from GH to Jenkins).
Build specific to that child-branch and its unique scm change and build history.
Automatic job pruning/deletion for branches deleted from the repository, according to the settings.
Flexibility to individually configure branch properties, by overriding the parent properties, if required.
To configure the webhooks, refer to this page.
To check if the events notify your jenkins you can use this feature below:
PS: Watch the URL target that you configured, if you miss the "/" at the end of url it might not be able to reach the jenkins.
I hope this helps!

Resources