01
パイプライン
宣言型パイプライン
Groovy DSL による宣言型パイプライン。
jenkins
pipeline {
agent any
stages {
stage("Build") {
steps { sh "npm run build" }
}
stage("Test") {
steps { sh "npm test" }
}
stage("Deploy") {
steps { sh "deploy.sh" }
}
}
}環境変数
環境変数とクレデンシャル。
jenkins
pipeline {
environment {
NODE_ENV = "production"
API_KEY = credentials("api-key")
}
}02
主な機能
when
条件に応じてステージを実行します。
jenkins
stage("Deploy") {
when { branch "main" }
steps { sh "deploy.sh" }
}post
ビルド後のアクションを定義します。
jenkins
post {
success { echo "Build passed" }
failure { emailext to: "[email protected]", subject: "Build failed" }
always { archiveArtifacts "dist/**" }
}parallel
ステージを並列実行します。
jenkins
stages {
stage("Test") {
parallel {
stage("Unit") { steps { sh "npm run test:unit" } }
stage("E2E") { steps { sh "npm run test:e2e" } }
}
}
}Was this helpful?