Here's is an example jobs
section of jenkins.yml
(CasC config file); it requires the "Job DSL" and "Startup Trigger" plugins (in addition to the "Configuration as Code" plugin, of course):
jobs:
- script: >
pipelineJob("Deploy Local2 Stack") {
description()
keepDependencies(false)
triggers {
hudsonStartupTrigger {
nodeParameterName("master")
label("master")
quietPeriod("0")
runOnChoice("False")
}
}
definition {
cpsScm {
scm {
git {
remote {
url("https://myrepo/mystuff.git")
credentials("scm")
}
branch("master")
}
}
scriptPath("pipeline/main/Jenkinsfile")
}
}
disabled(false)
}
The triggers
section is what's important; the rest is just to put it in context.
Apparently, the startup trigger can also work on slave nodes but I gather that's not what you want, so I specified master
.
Note: This is the kernel from which I pieced together the solution: https://issues.jenkins-ci.org/browse/JENKINS-41671?focusedCommentId=287026&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-287026