[Jenkins] Snippets¶
主に以下を参照。
Using a Jenkinsfile
Using a Jenkinsfile
Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software
Pipeline Syntax
Pipeline Syntax
Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software
よく使うコマンド¶
トリガー (定期実行など)¶
pipeline {
triggers {
cron('H */4 * * 1-5')
}
パラメータ¶
pipeline {
agent any
parameters {
string(name: 'Greeting', defaultValue: 'Hello', description: 'How should I greet the world?')
}
stages {
stage('Example') {
steps {
echo "${params.Greeting} World!"
}
Warning
shの内部で呼び出す時は ${params.Greeting}
ではなく ${Greeting}
なので注意
独自関数¶
Slack通知¶
def sendToSlack(channel, username, icon_emoji, color, text) {
sh "curl -s -S -X POST --data-urlencode 'payload={\"link_names\": 1, \"channel\": \"$channel\", \"username\": \"$username\", \"icon_emoji\": \":$icon_emoji:\", \"attachments\": [{\"color\": \"$color\", \"text\": \"$text\"}]}' $SLACK_INCOMING_WEBHOOKS_URL"
}