こちらのページで、概要を把握
http://tech.smarthr.jp/entry/2017/07/12/073000
移行手順の公式ドキュメント
https://circleci.com/docs/2.0/migrating-from-1-2/
config-translation Endpointを使うドキュメント
https://circleci.com/docs/2.0/config-translation/
config-translation Endpointを使って、設定ファイルを取得する。
CircleCIでのビルドページが次のURLだとする。
https://circleci.com/gh/:username/:project
上の場合、config-translation Endpointは、次のようなURLになる。
ここでは、ブランチをdevelop
に指定している。
https://circleci.com/api/v1.1/project/github/:username/:project/config-translation?branch=develop
config-translation
というファイル名で、ファイルがダウンロードされる。
NGパターン
:username
に、自分のGitHubアカウントのユーザーネームを設定してしまい、次のレスポンス結果になった。
{
"message" : "{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/repos/#get\"}"
}
ダウンロードした設定ファイルをプロジェクトに取り入れる。
次を参考に
https://circleci.com/docs/2.0/migrating-from-1-2/
.circleci
フォルダをプロジェクトルートに作成し、そこに、ダウンロードした設定ファイルを移動し、ファイル名をconfig.yml
に変更する。
$ mkdir .circleci
$ mv /hoge/config-translation .circleci/config.yml
Deployment
に関する記述を追記する。
ダウンロードした設定ファイルには、Deployment
は、まったく記述がないため、自分で記述する必要がある。
mvn integration-test
でエラーが発生する。
# !/bin/bash --login
mvn integration-test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.104 s
[INFO] Finished at: 2018-04-09T04:25:24+00:00
[INFO] Final Memory: 15M/904M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/home/ubuntu/topgate/hogehoge/server). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
Exited with code 1
pom.xmlがないと言われる。
pom.xmlは、/server/pom.xml
に存在している。
1.0
では、次の記述で、OKだった。
general:
build_dir: server
2.0
では、次のように変換されているが、working_directory
にチェックアウトしてしまうので、~/topgate/hogehoge/server
ではなく、~/topgate/hogehoge/server/server
に、pom.xml
が存在し、pom.xml
がないとエラーになっていた。
version: 2
jobs:
build:
working_directory: ~/topgate/hogehoge/server
解決策として、次の2つを思いつく。
案① mvnコマンドを実行するときのオプションに、working_directory: ~/topgate/hogehoge/server/server
を設定する。
- run:
working_directory: ~/topgate/hogehoge/server/server
command: mvn dependency:go-offline || true
案② チェックアウトコマンドに、path: ~/topgate/hogehoge
を設定して、1つ上の階層フォルダを指定する。
- checkout:
path: ~/topgate/hogehoge
config.ymlではまったこと
workflowsが動作しなくて、次の記述の違いに気づかず、はまった。
NGパターン(filters
が、build
と同格の位置になる。)
jobs:
- build:
filters:
tags:
only: /.*/
OKパターン(filters
が、build
の子の位置になる。)
jobs:
- build:
filters:
tags:
only: /.*/
git tag
で、ジョブが反応しない
1.0
では、git tag
でデプロイさせるために、次の記述をしていた。
deployment:
prod:
tag: /release-.*/
# ・・・・・・・・・・・・・・・・・・・・・・・・略・・・・・・・・・・・・・・・・・・・・・・・・
dev:
branch: develop
2.0
では、git tag
でジョブが起動せず、workflows
を使って、ジョブが起動するようにした。
Git Tag Job Execution
https://circleci.com/docs/2.0/workflows/#git-tag-job-execution
2.0
のジョブは、デフォルトでは、branch変更に反応するが、tag付けに反応しない。
なので、tag付けでジョブが起動するように、filters
を使って、tag用のフィルターを作る必要がある。
実際には、次のように記述した。
version: 2
jobs:
build:
# ・・・・・・・・・・・・・・・・・・・・・・・・略・・・・・・・・・・・・・・・・・・・・・・・・
- deploy:
name: deploy to prod
command: |
if [[ "${CIRCLE_TAG}" =~ ^release-.* ]]; then
# ・・・・・・・・・デプロイコマンド(略)・・・・・・・・・・
fi
- deploy:
name: deploy to dev
command: |
if [ "${CIRCLE_BRANCH}" == "develop" ]; then
# ・・・・・・・・・デプロイコマンド(略)・・・・・・・・・・
fi
# ・・・・・・・・・・・・・・・・・・・・・・・・略・・・・・・・・・・・・・・・・・・・・・・・・
workflows:
version: 2
build-deploy:
jobs:
- build:
filters:
tags:
only: /.*/