Use codebase connector's Git credentials in a CI Run step
Harness CI supports seamless integration with version control systems through codebase connectors. While most Git tasks are automated within the CI pipeline, there can be scenarios where you need to manually execute Git commands in a Run step, such as when you need to Clone a subdirectory or run use Git Large File Storage.
To facilitate this process, you can use a .netrc file to pull Git credentials from your pipeline's codebase connector and use those credentials in your Run step's commands.
Configure your CI pipeline's codebase.
Make sure to select the code repo connector with the credentials that you want to use in the Run step.
Add a Run step that creates a
.netrcfile with the following content:cat <<EOF > ${HOME}/.netrc machine ${DRONE_NETRC_MACHINE} login ${DRONE_NETRC_USERNAME} password ${DRONE_NETRC_PASSWORD} EOFIn the same Run step, add your Git commands. Git automatically uses the credentials from the
.netrcfile for authentication, enabling seamless manual Git operations.For example:
# Create the .netrc file cat <<EOF > ${HOME}/.netrc machine ${DRONE_NETRC_MACHINE} login ${DRONE_NETRC_USERNAME} password ${DRONE_NETRC_PASSWORD} EOF # Run Git commands git clone https://github.com/your/private-repo.git cd private-repo git pull origin main
Last updated
Was this helpful?