AWS re:Postを使用することにより、以下に同意したことになります AWS re:Post 利用規約

CDK CodeBuild Pipeline - possible to skip a phase on last github commit message?

1

Hi,

Is it possible to skip a phase in the buildspec based on last github commit message on the selected branch? For example, if the commit message includes "SKIP_BUILD"/"SKIP_TEST"/"SKIP_DEPLOY" then skip the relevant phase(s).

質問済み 2年前1709ビュー
1回答
1
承認された回答

Currently, AWS CodePipeline does not support skipping a stage or an action. However, there is an existing feature request for AWS CodePipeline to support skipping a stage or action. Additionally, there is also a feature request to skip a pipeline execution completely.

While I have no information on whether/when this feature may be released, I encourage you to keep an eye on our What's New pages for any new feature announcements.

As a workaround, you can implement an AWS Step Functions stage in your pipeline. That stage would decide whether to execute particular child stages based on your criteria. In this blog post, you can read about implementing a Step Functions stage in a CodePipeline. Step Functions can call CodeBuild or CodeDeploy actions or even execute another CodePipeline.

If you want to skip some particular actions in a CodeBuild stage itself, you can manually get the last commit message and decide. Here's an idea of what you buildspec script might contain:

CODEBUILD_COMMIT_MESSAGE="$(git log -1 --pretty=%B)"
if [[ $CODEBUILD_COMMIT_MESSAGE == *"SKIP_BUILD"* ]]; then
    echo "Skipping build actions"
else
    build.sh
fi
profile pictureAWS
回答済み 2年前
profile picture
エキスパート
レビュー済み 5ヶ月前
  • Hi, Thank you for your reply. Do you know how I can put multiline commands (Such as conditionals) in my buildspec in CDK? Here is a starter buildspec I've written:

              version: '0.2',
              phases: {
                install: {
                  commands: [
                    `CODEBUILD_COMMIT_MESSAGE="$(git log -1 --pretty=%B)"`
                  ],
                  onFailure: 'ABORT'
                },
                pre_build: {
                  commands: [
                    `if [[ $CODEBUILD_COMMIT_MESSAGE == *"SKIP_BUILD"* ]]; then`,
                    `echo "Skipping build actions"`,
                    `else`,
                    `build.sh`,
                    `fi`
                  ],
                  onFailure: 'ABORT'
                },
                build: { commands: [`echo reached home safely`] },
                post_build: { commands: [`echo reached home safely`] }
              },
              proxy: {
                uploadArtifacts: 'no'
              }
            }),```
  • Unfortunately, JSON does not allow multi-line strings which you need for conditional shell commands. You can use the \n control character, but this affects the readability. Alternatively you can write your buildspec in YAML because YAML is the native format for buildspecs: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html. Use the | character for a multi-line string value in YAML. CDK does not expose a method to inline a YAML buildspec at synth-time. You could do this yourself by parsing existing YAML into a JS object and passing the result to BuildSpec.fromObject.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ