Al K
Al K

Reputation: 71

Azure DevOps/TFS $(SYSTEM.ACCESSTOKEN) in docker container clone of the git repo

I have an issue. We're running build on build agent in a docker container. Maven plugin release:prepare needs to clone repo. When it does that it fails. So I have passed into the container $(SYSTEM.ACCESSTOKEN) as environment variable named "TFS_ACCESSTOKEN" (added additional argument -e TFS_ACCESSTOKEN="$(SYSTEM.ACCESSTOKEN)") and run this

git config --global http.extraheader "AUTHORIZATION: bearer ${TFS_ACCESSTOKEN}"

When plugin runs clone it still asks to provide user name and fails. I have changed my pipeline to output access token as base64 and set sleep for 1h. Decoded token, then go to another machine and repeat those steps manually all works. The steps:

git config --global http.extraheader "AUTHORIZATION: bearer <decoded-token>"
git clone https://tfs-server/repo-path

I wonder why the token works on 2 different machines and doesn't work in a container.

I have noticed that machines have the same /etc/machine-id. I have added volume to docker container and it still did not work.

Upvotes: 1

Views: 3742

Answers (2)

Al K
Al K

Reputation: 71

The problem was just because the Docker container had a very old version (1.8.3) of git, while the http.extraheader was introduced in 2.1.* (if I'm not mistaken).

Upvotes: 1

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

You need to wrap TFS_ACCESSTOKEN in $() to reference to it, rather than ${}.

Try changing below git command of yours

git config --global http.extraheader "AUTHORIZATION: bearer ${TFS_ACCESSTOKEN}"

To

git config --global http.extraheader "AUTHORIZATION: bearer $(TFS_ACCESSTOKEN)"

Upvotes: 2

Related Questions