Use same http git credentials as for cloning in a

2019-07-27 00:59发布

I want to automate our Release process and I have a following Jenkins build job for a Maven project:

  • Cloning a Git repo with configured Jenkins Credentials (username/password)
  • Executing some Maven commands for the build
  • Having a Post Step configured which executes some additional Git commands: merge, tag, push

If I run the build I receive following error during executing my Post Step Shell script:

fatal: could not read Username for 'https://mygitserver': Input/output error

The Git Repo server uses HTTP for Authentication.

In the Console Log I can see that Jenkins uses .gitcredentials to handle the Authentication:

using .gitcredentials to set credentials
> git config --local credential.username jenkins # timeout=10
> git config --local credential.helper store --file=/tmp/git2442727044778485.credentials # timeout=10

I would like now to reuse actually these credential store because they are created at the beginning of my build, but are removed again after cloning.

Is this somehow possible or do I need to handle this somehow by myself with the "Credentials Binding Plugin", etc.?

2条回答
SAY GOODBYE
2楼-- · 2019-07-27 01:23

Because I haven't found yet any solution to reuse the initial Git credentials from the clone command at the beginning of my build, I have just used now the Jenkins Credentials Binding plugin and created a own credentials store for my custom git commands in the Post Step.

查看更多
何必那么认真
3楼-- · 2019-07-27 01:36

Here is a path I took in order to fulfil a similar need:

  • I added a public ssh key in my git account
  • I added the ssh private key and passphrase as ssh credential in jenkins
  • I used this credential in my git repo clone phase
  • I reused the same credential in my ssh agent jenkins build environment ** hence all post build shell script will use it
查看更多
登录 后发表回答