5. Triggers¶
5.1. Webhook¶
Webhook trigger for GitScm polling
5.2. Cron¶
cron()
Accepts a cron-style string to define a regular interval at which the Pipeline should be re-triggered
triggers {
cron('H */4 * * 1-5')
}
5.3. Poll SCM¶
pollSCM()
Build periodically
Accepts a cron-style string to define a regular interval at which Jenkins should check for new source changes
If new changes exist, the Pipeline will be re-triggered
Available since Jenkins 2.22
triggers {
pollSCM('H */4 * * 1-5')
}
5.4. Upstream¶
Build after other projects are built
upstream()
Accepts a comma separated string of jobs and a threshold
When any job in the string finishes with the minimum threshold, the Pipeline will be re-triggered.
triggers {
upstream(upstreamProjects: 'job1,job2',
threshold: hudson.model.Result.SUCCESS)
}
5.5. REST API¶
Trigger builds remotely (e.g., from scripts via REST API)
curl -X POST http://localhost:8080/job/JOB_NAME/build \
--user USER:TOKEN \
--data-urlencode json='{
"parameter": [
{"name":"id", "value":"123"},
{"name":"verbosity", "value":"high"}
]}'
5.6. Example¶
pipeline {
agent any
triggers {
cron('@daily')
}
stages {
stage("Test") {
steps {
sh '/bin/echo Testing...'
}
}
}
}
5.7. Assignments¶
5.7.1. API Trigger¶
Napisz skrypt
sh
wykorzystującycurl
Skrypt po odpaleniu ma triggerować build
Dodaj skrypt do
crontab
Skrypt ma się uruchamiać
@daily
Zwróć uwagę, że
cron
ma mniejszą ilość zmiennych środowiskowych (skrypt, który u Ciebie działa, może nie być odpalany przezcron
)