Git credentials when npm has a git dependency
You can vend HTTPS credentials to git using the credential-helper config with a file. The file format is just an HTTPS URL with the user:password
credentials part filled in. Something like:
CREDENTIALS_FILE_PATH="$HOME/.git/my-ci-credentials"cat 'https://ci-user:ci-password@myRepoHost.example.com/' > "$CREDENTIALS_FILE_PATH"
Because npm clones the repo outside the context of your project folder, you'll need to specify this config at the user, rather than project, level:
git config --global credential.helper "store --file=$CREDENTIALS_FILE_PATH"
After this, npm should be able to clone the repo.
I solved this by using the git+ssh way of installing the dependency, like git+ssh://my-server/my-repo.git#1.0.0
Then on the Jenkins .ssh
folder add a config
file with the content:
Host github.comHostName github.comUser gitIdentityFile ~/.ssh/<rsa file>
Then Jenkins knows to use that ssh key for any github.com url. You need to have a Jenkins git user or deploy key associated with the project you are trying to import.