problems changing triggers{} in multibranch pipeline Jenkinsfile

140 views
Skip to first unread message

Tim Black

unread,
Oct 3, 2019, 8:03:17 PM10/3/19
to Jenkins Users
We have a multibranch pipeline job set up to scan a git repo (which contains Jenkinsfile at its root) for branches and create branch-specific jobs for each branch discovered. The Jenkinsfile on a branch specifies:

    triggers {
        cron('@midnight')
    }

and this indeed runs nightly at midnight. However, when I delete the above block and commit the Jenkinsfile to my branch, it appears to have no effect. Last night the build still ran at midnight. This is my problem.

I confirmed the change by looking on the branch job configuration page and indeed see an empty BuildTriggers section. There are no triggers specified and none of the trigger checkboxes are checked.

Please confirm whether this is indeed the way I am supposed to disable a trigger specified in a multibranch pipeline Jenkinsfile. 

Also, note that in the top-level pipeline job configuration, BranchSources is set up so "All branches get same properties" and set the property "Suppress Automatic SCM Triggering" because we only want builds to be done nightly for now, and not as a result of commits. Also, "Scan Multibranch Pipeline Triggers" is configured to scan our repo every minute for branch changes. I assume this means that it also scans and applies any changes to Jenkinsfiles (e.g. our trigger {} changes) to the branch job. I believe this to be happening, bc as I've said, the job configuration page seems to have reflected our change to the Jenkinsfile in SCM. But the build still was triggered last night at midnight.

Please let me know if you know what's going wrong here, or have any suggestions for troubleshooting this.

Thanks,
Tim

Björn Pedersen

unread,
Oct 4, 2019, 4:52:07 AM10/4/19
to Jenkins Users
Hi,


Am Freitag, 4. Oktober 2019 02:03:17 UTC+2 schrieb Tim Black:
We have a multibranch pipeline job set up to scan a git repo (which contains Jenkinsfile at its root) for branches and create branch-specific jobs for each branch discovered. The Jenkinsfile on a branch specifies:

    triggers {
        cron('@midnight')
    }

and this indeed runs nightly at midnight. However, when I delete the above block and commit the Jenkinsfile to my branch, it appears to have no effect. Last night the build still ran at midnight. This is my problem.

I confirmed the change by looking on the branch job configuration page and indeed see an empty BuildTriggers section. There are no triggers specified and none of the trigger checkboxes are checked.

Please confirm whether this is indeed the way I am supposed to disable a trigger specified in a multibranch pipeline Jenkinsfile. 



The update to the job config for changes made in the jenkinsfile only happen once  the jobs runs (before that point, the jenkinsfile is neither fetched nor evaluated). So if you changed the trigger today, then it would run once tonight and should stop starting after that.  To get the effect more immedeatly, you could trigger the job manually.

Björn

Tim Black

unread,
Oct 4, 2019, 6:55:47 PM10/4/19
to Jenkins Users
Thanks Bjorn for helping clarify that. I would take what you said a step further by changing "could" to "must", since it appears that simply adding a trigger back into a Jenkinsfile for a job that has run since the trigger was removed, will necessarily have no effect until you manually run the job.

Paraphrasing, and I wish this was in the docs somewhere, "Multibranch Pipeline job properties specified in a Jenkinsfile, e.g. triggers, agents.. have no effect until the job is run."

This is perhaps obvious to those with more experience with this plugin's SCM scanning feature.

Perhaps another good way to say it would be in the section that talks about the scanning feature to call out that "the scanning only looks at Jenkinsfile existence, it does not apply changes made inside Jenkinsfiles until they are run."

Reply all
Reply to author
Forward
0 new messages