Git credentials when npm has a git dependency
git, jenkins, npm
Solution
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"
echo '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.
Problem
I have a Jenkins job to build my JS application. In my `package.json` I have a dependency that looks like this: ``` "devDependencies": { "my_private_package": "git+https://my-server/my-repo.git#1.0.0" } ``` I use the Jenkins Git Plugin along with the Credentials Plugin to clone the repo, then a shell script to run `npm install`. When Jenkins runs `npm install`, `npm` errors out with `npm ERR! fatal: Authentication failed` Due to our self hosted git server and bureaucracy I'm unable to do anything with adding an oAuth token to the git url. Is there a way for me to set my git credentials so that npm can install from my password protected git repo?