I am trying to optimise a build step in my pipeline by doing only a partial clone of the repository.
For context: I got some large media files in the repository which are not neede when building JS and CSS resources. So I am trying to exclude them from from being cloned and checked out.
In a related thread (https://community.atlassian.com/forums/Bitbucket-questions/Can-I-clone-the-repository-in-a-pipeline-only-once-if-the-runner/qaq-p/2584299) someone from the Atlassian Team suggests the following:
In this case, I believe the best approach would be to disable clone in your YAML entirely and just manually clone your repository in the first step.
Sadly, they do not elaborate on how exactly to go about manually cloning the repository.
I tried including the clone command from the pipeline log in my step script like this:
defitions:
steps:
- step: &build
name: Build
image: larsebert/php8-composer-dartsass:latest
script:
- git clone -n --filter=blob:none --depth=1 https://x-token-auth:$REPOSITORY_OAUTH_ACCESS_TOKEN@bitbucket.org/$BITBUCKET_REPO_FULL_NAME.git $BUILD_DIR
- cd $BUILD_DIR
- git sparse-checkout set --no-cone '/*' '!/webroot/media'
- git checkout --force $BITBUCKET_COMMIT
- composer install --no-scripts
- mkdir webroot/js && php bin/cake.php asset_compress build
- mkdir webroot/css && sass --no-source-map --style=compressed resources/scss:webroot/css
However, this results in the error message "remote: Invalid credentials" since apparently the variable `
$REPOSITORY_OAUTH_ACCESS_TOKEN` is not available in the build script.
Is there any easy way to gain access to the repository?
By the way: The ability to do a sparse checkout like this using the pipeline clone options instead of doing a manual clone would be awesome. I imagine this would be a common use case.
Hi Advitum,
You don't actually need to disable the clone to specify the clone depth that is performed, you can simply specify the clone depth in your YAML configuration - for example:
pipelines:
pipelines:
Please let me know if you require further assistance.
Cheers!
- Ben (Bitbucket Cloud Support)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.