Cirrus-ci-docs: How to clone a GH repository with submodules?

Created on 7 Aug 2019  路  7Comments  路  Source: cirruslabs/cirrus-ci-docs

Question

My GH repository has a important submodule which is required for the build.
What method can I use to clone (--init --recursive) that repo?

I had overwritten the clone_script part before like so:

  clone_script:
    - git clone --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
    - git submodule update --init --recursive

However, that fails as the module will be configured in .gitmodules with a different URL.

Is it advised to "re-add" the module in this case by build a URL which contains the clone token as above? Will the CIRRUS_REPO_CLONE_TOKEN work for submodules (different than the actual GH repo which caused the build)?

question

All 7 comments

@ened is it for a public repository? I know it usually works without a problem with the build-in Git client like this:

task:
  submodules_script:
    - git submodule init
    - git submodule update

@fkorotkov no, they are private repositories, but hosted on GitHub.

Would that still work?

Yeah, that will work. Was just wondering if it's for a public repo then I could've check it for you.

If you don't have a particular reason to not use the built-in Git client, then I'd suggest you to try to remove your custom clone_script and add the submodules_script instead.

Closing the issue since seems the question is answered. Please re-open if the proposed solution didn't work for you.

@fkorotkov, I follow your instructions (adding the submodules_script) but I cannot make it work using private repos as submodules
Here is the log:

git submodule init
Submodule 'submodule1' (https://github.com/org/submodule1.git) registered for path 'submodule1'
git submodule update
Cloning into '/tmp/cirrus-ci-build/submodule1'...
fatal: could not read Username for 'https://github.com': No such device or address
fatal: clone of 'https://github.com/org/submodule1.git' into submodule path '/tmp/cirrus-ci-build/submodule1' failed
Failed to clone 'submodule1'. Retry scheduled
Cloning into '/tmp/cirrus-ci-build/submodule1'...
fatal: could not read Username for 'https://github.com': No such device or address
fatal: clone of 'https://github.com/org/submodule1.git' into submodule path '/tmp/cirrus-ci-build/submodule1' failed
Failed to clone 'submodule1' a second time, aborting

I also tried using the SSH way to define the submodules in .gitmodules file and it fails with the following authentication error:

Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

What if you'll add the following:

git config --global url."https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github".insteadOf https://github

Found it here.

I think the issue may stem from submodules being includes via ssh ( url = [email protected]:ened)..

@fkorotkov does ssh authentication for submodules need special configuration?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fkorotkov picture fkorotkov  路  4Comments

awnumar picture awnumar  路  5Comments

RDIL picture RDIL  路  4Comments

aslushnikov picture aslushnikov  路  5Comments

dotdoom picture dotdoom  路  5Comments