• 製品
  • 使用を開始する
  • 関連ドキュメント
  • リソース

Jenkins によるデプロイのゲーティングを使用する

デプロイのゲーティングを使用して、Jenkins パイプラインのいずれかの段階で承認ゲート付きの変更リクエストを作成します。パイプラインが変更リクエスト Jira ワークフローのステータスの使用を継続すべきかどうか (および、いつ継続すべきか) を制御します。関係者は、Jira Service Management からのデプロイを許可または阻止できます。

Jenkins によるデプロイ ゲーティングを使用するには、次の手順を実行します。

  1. Jenkinsfile に移動します。

  2. 変更リクエストを起票したいパイプラインの段階を見つけます。たとえば、「本番」デプロイ段階前などです。

    • デプロイのエーティング用に、パイプラインに 2 つの段階を追加することをお勧めします。変更リクエストを発行する段階と、もう変更リクエストのステータスをチェックする段階です。

  3. 次のスニペットをパイプラインに追加して、Jira Service Management プロジェクトからコピーした Jira サイト名、環境 ID、環境タイプサービス ID を置換します。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 stage('Request approval') { // Raise change request steps { echo 'Raise change request...' jiraSendDeploymentInfo(site:'<YOUR-SITE>.atlassian.net', environmentId:'us-prod-1', environmentName:'us-prod-1', environmentType:'production', state:"pending", enableGating:true, serviceIds: [ '<YOUR-SERVICE-ID>' ] ) } } stage("Approval gate") { // Check request status steps { retry(20) { // Poll every 30s for 10min waitUntil { sleep 30 checkGatingStatus( site:'<YOUR-SITE>.atlassian.net', environmentId:'us-prod-1' ) } } } }

スニペットの例: ゲーティングされた変更リクエストを起票します

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 stage('Request approval') { // Raise change request steps { echo 'Raise change request...' jiraSendDeploymentInfo(site:'<YOUR-SITE>.atlassian.net', environmentId:'us-prod-1', environmentName:'us-prod-1', environmentType:'production', state:"pending", // Deployment has not started yet enableGating:true, // Notify Jira the pipeline is gated serviceIds: [ '<YOUR-SERVICE-ID>' ] ) } }

スニペットの例: 変更リクエスト ステータスを手動でチェックします

1 2 3 4 5 6 7 8 9 10 11 12 stage("Approval gate") { steps { waitUntil { input message: "Check for approval?" // Manually trigger check status checkGatingStatus( site:'<YOUR-SITE>.atlassian.net', environmentId:'us-prod-1' ) } } } }

スニペットの例: 遅延後に自動的に変更リクエスト ステータスをチェックします

1 2 3 4 5 6 7 8 9 10 11 12 stage("Approval gate") { steps { waitUntil { sleep 30 // check status after 30s checkGatingStatus( site:'<YOUR-SITE>.atlassian.net', environmentId:'us-prod-1' ) } } } }

スニペットの例: 自動的に変更リクエスト ステータスをチェックします (ポーリング)

1 2 3 4 5 6 7 8 9 10 11 12 13 stage("Approval gate") { steps { retry(20) { // Retry every 30s for 10min waitUntil { sleep 30 checkGatingStatus( site:'<YOUR-SITE>.atlassian.net', environmentId:'us-prod-1' ) } } } }

完全な Jenkinsfile の例

変更リクエストを起票し、本番へのデプロイ前に承認を待ちます。承認が完了したら、自動的にパイプラインを再開します。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 pipeline { agent any stages { stage("Test") { steps { echo "Deploying to test" } } stage("Stage") { steps { echo "Deploying to staging" } } stage('Request approval') { // Raise change request steps { echo 'Raise change request...' jiraSendDeploymentInfo(site:'<YOUR-SITE>.atlassian.net', environmentId:'us-prod-1', environmentName:'us-prod-1', environmentType:'production', state:"pending", enableGating:true, serviceIds: [ '<YOUR-SERVICE-ID>' ] ) } } stage("Approval gate") { // Check change request status steps { retry(20) { // Poll every 30s for 10min waitUntil { sleep 30 checkGatingStatus( site:'<YOUR-SITE>.atlassian.net', environmentId:'us-prod-1' ) } } } } stage("Production") { steps { echo "Deploying to production!!" } post { always { sh 'sleep 2' } // Notify Jira based on deployment step result success { jiraSendDeploymentInfo ( site: '<YOUR-SITE>.atlassian.net', environmentId: 'us-prod-1', environmentName: 'us-prod-1', environmentType: 'production', state: 'successful', serviceIds: [ '<YOUR-SERVICE-ID>' ] ) } } } } }

 

その他のヘルプ