We are using https to clone a repo as following through Jenkins build:
git clone https://${repo_username}:${repo_password}@internalgit.com/scm/project/repo.git -b ${branch_name} $tmp
In above command: ${repo_username} & ${repo_password} are Jenkins variables passed as secrets so they are not logged as clear text.
However, this adds the user credentials to the git remote URL and in case of any push failure it shows the credentials in clear text in the following error:
[ERROR] To https://user:password@internalgit.com/scm/project/repo.git
[ERROR] ! [remote rejected] master -> master (pre-receive hook declined)
[ERROR] error: failed to push some refs to 'https://user:password@internalgit.com/scm/project/repo.git'
There can be a number of valid reasons for a push failure, however, printing credentials on screen is not acceptable.
Is there a way either to:
- mask the above error message.
- updating the remote URL to lose the password, without the password once again being prompted during push.
Following work arounds work but NOT acceptable in our use case:
- Store password in credential cache (using credential.helper)
- Using ssh clones instead of https.