Do Jenkins multibranch Pipelines allow remote triggers? - jenkins

I am trying to to allow my multibranch Jenkins Pipeline to be triggered from a script. However each time I check the box and enter my token name and hit save, it does not save the configuration. When I next hit edit configuration the checkmark next to "Trigger builds remotely" is no longer checked.
Is this intentional? Do MultiBranch Pipeline jobs not support remote triggers?

Actually, for now, it is possible to trigger the build of a multibranch pipeline, but the token is simply ignored.
If you go in a branch of your multibranch pipeline and go to "View Configuration", you can try to check "Trigger builds remotely (e.g., from scripts)" and see that it gives you a link like JENKINS_URL/job/<your-multibranch-pipeline>/job/<your-branch>/build.
That sounds a bit like a hack, and you might have authentication problems depending on your setup, but otherwise it does trigger the build with Jenkins 2.30.

I have the same problem. Haven't found a solution yet, but there is a bug report open against it.

Related

Can't configure Scan Multibranch Pipeline Triggers in Jenkins Pipeline

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.

Jenkins missing Build Trigger section after upgrade

I've upgraded Jenkins version (now on 2.127) and plugins and now the UI of job configuration is different and I am missing the build triggers section, especially the Trigger Builds Remotely via authentication token. Where is it? Do I need to enable it explicitly? The changelog unfortunately does not mention anything about that and I even can't schedule builds periodically.
Finally found out: It seems that since the update, the Multibranch Pipeline does no longer have this section. So either choose Pipeline or set it in the Jenkinsfile via: https://github.com/jenkins-infra/jenkins.io/blob/c0828af5b8bd428815e23537c808cd0267017013/Jenkinsfile#L6
The webhook works without a token with the Generic Webhook Plugin.

Jenkins edit config in multi-branch pipeline

I cannot find a way to edit the configuration of multibranch pipeline projects. When I change to the branch level, there is only a "view configuration" menu item, as opposed to ordinary pipeline projects.
I am looking for a method to configure build triggers from outside Jenkins. My current workaround (define a pipeline per branch) is not feasible beyond initial testing.
You can edit the overall configuration of a multi-branch pipeline project, such as the repo it will read from and any credentials it will need, triggers for scanning the branch to check for changes (Note: not the same as build triggers),orphaned item strategy, build configuration, properties, and a few other things. This can be viewed by clicking "Configuration" on the page that shows all the branches, or it will say it is empty if there are none.
Please note this only applies to multibranch pipelines that are not part of an organizational folder (not a "Bitbucket Team/Project" or "GitHub Organization" type project.)
If you click a branch name (ex: master), clicking "View Configuration" will only let you view it. You have to edit the file defining that pipeline on the correct branch in order to change it. In the case of these screen shots, you need to edit the Jenkinsfile in the Test-Multibranch-Job repo on the master branch to edit the configuration.
To add a trigger mechanism, you could add triggers { gitlab(<config-here>) } to your Jenkinsfile if your repo is in Gitlab. Also note whether you are using a declarative pipeline or a scripted pipeline because the syntaxes are different.
NOTE: I am running Jenkins ver. 2.92
https://issues.jenkins-ci.org/browse/JENKINS-33900
"As designed, these jobs are view-only." -- Jesse Glick
you should be able to define the config in the pipeline itself, e.g. https://jenkins.io/doc/book/pipeline/syntax/#triggers
If you are trying to edit a Multibranch configuration, for example to configure Multibranch Action Triggers which have no Jenkinsfile configuration, you can go edit the configuration file directly on your server, in /var/lib/jenkins/jobs/NAMEOFPROJECT/config.xml

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!

How to trigger a Jenkins build on a Perforce submit

I am using Jenkins with Perforce. I have downloaded the P4 Plugin, and I have read over the documentation but I am still a bit confused. In my Jenkins project, I have the build trigger set to "Perforce triggered build". I'm assuming that means I need to add a trigger to Perforce that tells Jenkins to run a build, but I have no idea on how to do that.
I have not been able to find any documentation on how to implement a trigger from Perforce to notify Jenkins it needs to run. I can find documentation from Perforce on how to setup basic triggers, but I can not find anything from Jenkins on how to set up the actual connection to trigger builds on Perforce submits.
On the "Changes" tab in Jenkins, I am able to see the what was submitted to Perforce, so I know that Perforce and Jenkins are at least communicating. Initially, I thought that Jenkins would just automatically run the build on a Perforce submit, if I had "Perforce triggered build" checked, but that doesn't seem to be the case.
So my questions are:
Am I correct in assuming that I need to manually create a trigger to be added to Perforce?
If so, does anyone know of any documentation or examples that I can look to as a guide?
Yes, you need to add a trigger to Perforce. It's well documented here.

Resources