5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CircleCI1.0から2.0に移行したときのメモ

Last updated at Posted at 2018-04-13

こちらのページで、概要を把握
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: /.*/
5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?