Jenkins for Jira の仕組み
この記事は、Jenkins for Jira アプリの仕組みを説明するリファレンス ガイドです。Jira チームによるサイトと Jenkins サーバー間の接続設定を手伝う Jenkins 管理者の参考になる場合があります。
ほとんどの場合、この技術的な詳細情報は Jira Software Cloud の管理者やプロジェクト チームには必要ありません。管理者やプロジェクト チームの方は、Jenkins for Jira アプリのガイド付きの接続プロセスや「Jenkins と連携する」の記事に従ってください。
Jenkins が Jira にデータを送信する方法
パイプラインが Jenkins で実行されるたびに、アトラシアン Jira Software Cloud プラグインは、そのパイプラインについて説明する Jenkinsfile を調べて、Jiraにデータを送信すべきサインがないか確認します。
プラグインは次の 2 つを検索します。
ビルドまたはデプロイの各ステージにおける特定の指示 (
jiraSendBuildInfo
とjiraSendDeploymentInfo
)。ビルドとデプロイの各ステージでの特定の命名規則 (プラグインが特定の命名規則を検索するように設定されている場合)
If the plugin finds either of these, it will look for Jira work item keys in the commit messages and branch names of code being built or deployed in those stage, respectively. If it finds these, it will send event data about those stages (such as whether a build was successful or failed) to Jira. If no work item keys are found, the plugin will not send data to Jira.
Jira が Jenkins からデータを受信する方法
When your Jira receives event data from Jenkins, the Jenkins for Jira app displays relevant event data in your Jira work items, on the deployment pipeline, and in the releases feature. The app discards any events that don’t contain work item keys relevant to your site.
必要なアクション
Jenkins からビルド データとデプロイ データを受け取るには、次の点に留意してください。
サーバーのパイプラインについて説明する Jenkinsfile には、アトラシアン Jira Software Cloud プラグインが Jira にデータを送信するタイミングが示されている必要があります
Your team must include Jira work item keys (e.g. FUSE-123) in their commit messages and branch names so Jenkins for Jira knows the event data from Jenkins is relevant to your site
Jira にデータを送信するように Jenkinsfile を設定する方法は次のとおりです。
ステージ名を使ってビルド データを Jira に送信する
Jenkinsfile に特定の指示を追加せずにビルド イベントを送信するには、次の手順を実行します。
[Jenkins の管理] > [Atlassian Jira Software Cloud] > [Advanced settings (optional) (詳細設定 (オプション))] の順に移動します。
[ビルドを自動送信] チェックボックスをオンにします。
これを有効にすると、パイプラインの実行が開始されると「進行中」の、パイプラインが正常に終了すると「成功」の、エラーにより停止すると「失敗」の各ビルド イベントが、プラグインから Jira に送信されます。
ビルドに正規表現も指定した場合、プラグインは一致する名前を持つビルド ステップが完了した後にのみ Jira にビルド イベントを送信します。
正規表現 ^build$
は、次の Jenkinsfile
のbuild
ステージに一致します。次に例を示します。
pipeline {
agent any
stages {
stage('build') {
steps {
echo 'build done'
}
}
}
}
この Jenkinsfile 内のパイプラインが実行されるたびに、build
ステージの開始時と終了時に、ビルド イベントをすべての設定済み Jira Cloud サイトに送信します。
ステージ名を使ってデプロイ データを Jira に送信する
Jenkinsfile に特定の指示を追加せずにビルド イベントを送信するには、次の手順を実行します。
[Jenkins の管理] > [Atlassian Jira Software Cloud] > [Advanced settings (optional) (詳細設定 (オプション))] の順に移動します。
[デプロイを自動送信する] チェックボックスをオンにします。
これを有効にすると、指定した正規表現と一致する名前のビルド ステップの実行が開始されると「進行中」の、ビルド ステップが終了すると「成功」または「失敗」の各ビルド イベントが、プラグインからJira に送信されます。
これを機能させるには、Jenkinsfile 内のデプロイ ステップの名前に環境名が含まれている必要があります。正規表現にはフラグメント ((?<envName>.*)
) を含めて環境名と一致させ、プラグインがビルド ステップ名から環境名を抽出できるようにします。
Jenkinsfile
の例を以下に示します。
pipeline {
agent any
stages {
stage('deployments') {
parallel {
stage('deploy to stg') {
steps {
echo 'stg deployment done'
}
}
stage('deploy to prod') {
steps {
echo 'prod deployment done'
}
}
}
}
}
}
[デプロイを自動送信する] チェックボックスがオンで正規表現が ^deploy to (?<envName>.*)$
に設定されている場合は、上記の Jenkinsfile を実行すると、stg
と prod
の各環境の「進行中」デプロイ イベントがすべての設定済み Jira Cloud サイトに送信されます。その後、ビルド ステップが完了するとそれぞれの「成功」デプロイ イベントが送信されます。
明示的な指示を使ってビルド データを Jira に送信する
ビルド イベントを送信するタイミングをより細かく制御する場合は、jiraSendBuildInfo
ビルド ステップを使用できます。
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
post {
always {
// previous to version 2.0.0 you must provide parameters to this command (see below)!
jiraSendBuildInfo()
}
}
}
}
}
This will send a "success" or "failure" build event to all configured Jira Cloud sites after the Build
stage has finished successfully or with an error. The Jenkins plugin will automatically extract Jira work item keys from the branch name.
また、Jira サイトの URL を指定して、ビルド イベントを (すべての設定済み Jira サイトではなく) この Jira サイトにのみ送信するようにプラグインに指示できます。
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
post {
always {
jiraSendBuildInfo site: 'example.atlassian.net', branch: 'TEST-123-awesome-feature'
}
}
}
}
}
明示的な指示を使ってデプロイ データを Jira に送信する
デプロイ イベントを送信するタイミングをより細かく制御する場合は、jiraSendDeploymentInfo
ビルド ステップを使用できます。
pipeline {
agent any
stages {
stage('Deploy - Staging') {
when {
branch 'master'
}
steps {
echo 'Deploying to Staging from master...'
}
post {
always {
jiraSendDeploymentInfo environmentId: 'us-stg-1', environmentName: 'us-stg-1', environmentType: 'staging'
}
}
}
stage('Deploy - Production') {
when {
branch 'master'
}
steps {
echo 'Deploying to Production from master...'
}
post {
always {
jiraSendDeploymentInfo environmentId: 'us-prod-1', environmentName: 'us-prod-1', environmentType: 'production'
}
}
}
}
これによって、Deploy - Staging
とDeploy - Production
の各ステージの終了時に、すべての設定済み Jira サイトに「成功」または「失敗」の各デプロイ イベントが送信されます。
パラメーター environmentId
、environmentName
、environmentType
を指定する必要があります。environmentType
は、unmapped
、development
、testing
、staging
、production
のいずれかである必要があります。
デプロイ イベントを、すべての設定済み Jira サイトではなく単一の Jira サイトに送信するように、パラメーター site
を指定できます。
複数の Jira サイトが Jenkins サーバーに接続されている場合は、enableGating:true
を指定した jiraSendDeploymentInfo
がsite
パラメーターに必要です。デプロイ ゲートの詳細についてはこちらをご参照ください。
You can also specify a branch with the branch
parameter to define the branch from which to extract Jira work item keys to connect the deployments with.
完全な Jenkinsfile の例
以下の Jenkinsfile
のように、ビルドとデプロイを組み合わせられます。
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
post {
always {
jiraSendBuildInfo site: 'example.atlassian.net'
}
}
}
stage('Deploy - Staging') {
when {
branch 'master'
}
steps {
echo 'Deploying to Staging from master...'
}
post {
always {
jiraSendDeploymentInfo environmentId: 'us-stg-1', environmentName: 'us-stg-1', environmentType: 'staging'
}
}
}
stage('Deploy - Production') {
when {
branch 'master'
}
steps {
echo 'Deploying to Production from master...'
}
post {
always {
jiraSendDeploymentInfo environmentId: 'us-prod-1', environmentName: 'us-prod-1', environmentType: 'production'
}
}
}
}
}
Jira で開発情報を表示する
Whenever you make a commit or merge a pull request in a connected source code management tool, like Bitbucket or GitHub, it should run the Jenkins pipeline you have specified for that repo. The development panel on your Jira work items will update to show any associated build and deployment information, as long as your team is including work item keys in their pull requests, commit messages, and branch names. Learn more about how to view development information for a work item.
If you’ve enabled the deployments feature in your Jira project, the Deployments page will show all your Jenkins deployments on a timeline. You can filter or search to view your deployments by environment, assignee, work type, and more. And if your team is using releases and versions to organize your work, you’ll also find deployment information in the Releases feature.
Jira Service Management Cloud を Jenkins とリンクする
Jenkins を Jira Service Management Cloud プロジェクトに接続する方法をご確認ください。
詳細
この内容はお役に立ちましたか?