【CircleCi】パイプラインを手動トリガーにする
はじめに
CICD導入+自分で1からAndroidアプリを作成しAppiumでE2Eテスト自動化をやってみて学んだことを備忘録として残しておく。
自分で1からAndroidアプリを作成してE2Eテスト自動化を行ったリポジトリは以下。
CircleCiのパイプラインのトリガー
デフォルトの設定について
基本的にはVCSへのpushをトリガーにしてパイプラインが走るようになっている。
push時にパイプラインが走らないようにするには、[ci skip]
とか[skip ci]
という文字列をコミットメッセージ or 説明に記載すればいい。1
By default, CircleCI automatically builds a project whenever you push changes to a version control system (VCS). You can override this behavior by adding a [ci skip] or [skip ci] tag anywhere in a commit’s title or description.
手動でパイプラインを実行する
手動のトリガーでCircleCiのパイプラインを実行したくなる場面も出てくるが、そんな時には、Web APIをcallすればいい。2
curl https://circleci.com/api/v2/project/<vcs-type>/<org>/<repo>/pipeline \
--request POST \
--header "Circle-Token: <API_KEY>"
-
<vcs-type>
CircleCiのconfig.yml
を置いているVCSのタイプ
ex) github -
<org>
CircleCiのorganizationの名前 -
<repo>
VCSのリポジトリ名(CircleCiのパイプラインでcheckoutするブランチのリポジトリ) -
<API_KEY>
CircleにアクセスするためのToken
また、この手動トリガー以外でパイプラインを実行させたくない場合には、yamlを以下のように記述し、curlコマンドも次のように変更する事でそれが実現できる。
JSON=$(cat << EOS
{
"branch": "main",
"parameters": {
"manual": true
}
}
EOS)
curl https://circleci.com/api/v2/project/<vcs-type>/<org>/<repo>/pipeline \
--request POST \
--header "Circle-Token: <API_KEY>"
--header "Content-Type: application/json" \
--data "${JSON}"
version: 2.1
parameters:
manual:
type: boolean
default: false
workflows:
run_pipeline:
when: << pipeline.parameters.manual >>
jobs:
- hoge
- fuga
上記のような実装したソースコード(yaml)全体は以下。
- GitHub Actionsのyml(CircleCiのworkflowをキックするパイプライン)
https://github.com/yuta-katayama-23/MobileAppE2ETest/blob/happybirthday-app/.github/workflows/circleci-manual-start.yml - CircleCiのyml(手動トリガーのみで実行されるように実装したパイプライン)
https://github.com/yuta-katayama-23/MobileAppE2ETest/blob/happybirthday-app/.circleci/config.yml#L10
Author And Source
この問題について(【CircleCi】パイプラインを手動トリガーにする), 我々は、より多くの情報をここで見つけました https://qiita.com/yuta-katayama-23/items/0f2ae509a482c6a52260著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .