LoginSignup
0
0

More than 5 years have passed since last update.

Spring Cloud Pipelinesでサブモジュールが取得できないときの解決方法

Posted at

Spring Cloud Pipelinesの資材をプライベートリポジトリに置いたとき、サブモジュールの取得に失敗してシードジョブ実行が失敗する現象が起きた。

原因

(おそらく)プライベートリポジトリに指定した認証情報でサブモジュールのリポジトリの認証を試みてエラーになるっぽい。
サブモジュールはGitHubのパブリックリポジトリ上にあるので、認証情報の不整合?が生じるのではないか。

解決策

強引だが、jenkins_pipeline.groovyを以下のように修正した。

  • submoduleOptionsの削除
    • これを指定したジョブを実行すると、親リポジトリ(ここでは、Spring Cloud Pipelinesの資材が置いてあるプライベートリポジトリ)の指定した場所にサブモジュールをダウンロードして配置する(おそらく、git clone --recursiveを呼び出すのと同義)。
    • 後述するgit submodule addコマンドを発行する代わりにこの記載を削除する
  • git submodule addコマンドの追加
    • サブモジュールの取得を個別にコマンドで行う。groovyからはshellメソッドで呼び出す

サブモジュール定義

spring-cloud-pipelines/直下にある.gitmodulesを開くと、以下の記載がある。
サブモジュールが置いてあるリポジトリのURLと、親リポジトリへの配置場所が定義されている。

[submodule "common/src/test/bats/test_helper/bats-assert"]
    path = common/src/test/bats/test_helper/bats-assert
    url = https://github.com/ztombol/bats-assert
[submodule "common/src/test/bats/test_helper/bats-support"]
    path = common/src/test/bats/test_helper/bats-support
    url = https://github.com/ztombol/bats-support
[submodule "common/src/test/bats/docs_helper/zshelldoc"]
    path = common/src/test/bats/docs_helper/zshelldoc
    url = https://github.com/zdharma/zshelldoc.git
[submodule "jenkins/src/test/bats/test_helper/bats-support"]
    path = jenkins/src/test/bats/test_helper/bats-support
    url = https://github.com/ztombol/bats-support
[submodule "jenkins/src/test/bats/test_helper/bats-assert"]
    path = jenkins/src/test/bats/test_helper/bats-assert
    url = https://github.com/ztombol/bats-assert

これを個別にコマンド化すると以下のようになる(WORKSPACEはJenkinsのジョブディレクトリ)。

git submodule add https://github.com/ztombol/bats-assert.git \${WORKSPACE}/common/src/test/bats/test_helper/bats-assert
git submodule add https://github.com/ztombol/bats-support.git \${WORKSPACE}/common/src/test/bats/test_helper/bats-support
git submodule add https://github.com/zdharma/zshelldoc.git \${WORKSPACE}/common/src/test/bats/docs_helper/zshelldoc
git submodule add https://github.com/ztombol/bats-assert.git \${WORKSPACE}/jenkins/src/test/bats/test_helper/bats-assert
git submodule add https://github.com/ztombol/bats-support.git \${WORKSPACE}/jenkins/src/test/bats/test_helper/bats-support

jenkins_pipeline.groovy修正前

import javaposse.jobdsl.dsl.DslFactory

DslFactory factory = this

factory.job('myapp-seed') {
    scm {
        git {
            remote {
                github('spring-cloud/spring-cloud-pipelines') // Spring Cloud PipelinesのGitHubのurl
            }
            branch('${TOOLS_BRANCH}')
            extensions {
                submoduleOptions {  // サブモジュール取得を再帰的に行う設定
                    recursive()
                }
            }
        }
    }
    steps {
        gradle("clean build -x test")

jenkins_pipeline.groovy修正後

import javaposse.jobdsl.dsl.DslFactory

DslFactory factory = this

factory.job('myapp-seed') {
    scm {
        git {
            remote {
                url('${TOOLS_REPOSITORY}')  // プライベートリポジトリに置いたSpring Cloud Pipelines資材のURL
                credentials('git') // Jenkinsで設定した認証情報を渡す
            }
            branch('${TOOLS_BRANCH}')
        }
    }
        // git submoduleコマンドを呼び出す
    steps {
        shell("export WORKSPACE=\$(pwd)")
        shell("git submodule add https://github.com/ztombol/bats-assert.git \${WORKSPACE}/common/src/test/bats/test_helper/bats-assert")
        shell("git submodule add https://github.com/ztombol/bats-support.git \${WORKSPACE}/common/src/test/bats/test_helper/bats-support")
        shell("git submodule add https://github.com/zdharma/zshelldoc.git \${WORKSPACE}/common/src/test/bats/docs_helper/zshelldoc")
        shell("git submodule add https://github.com/ztombol/bats-assert.git \${WORKSPACE}/jenkins/src/test/bats/test_helper/bats-assert")
        shell("git submodule add https://github.com/ztombol/bats-support.git \${WORKSPACE}/jenkins/src/test/bats/test_helper/bats-support")
        gradle("clean build -x test")

参考

さいごに

  • もっとよいやり方がある気がしてならない。
0
0
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
0
0