Pushing back to a repository from within a pipe returns error Failed to connect to localhost port 29418
プラットフォームについて: Cloud のみ - この記事は クラウド プラットフォームのアトラシアン製品に適用されます。
要約
When executing a git push command from within a pipe/custom pipe, and to the same repository where the Pipeline is running, an error similar to the following is returned :
fatal: unable to access 'http://bitbucket.org/<workspace>/<repository>/': Failed to connect to localhost port 29418: Connection refused
環境
- Bitbucket Pipelines on Bitbucket Cloud
原因
Bitbucket Pipelines set up an internal proxy for git at the start of the build process so you don't have to manually configure authentication in case you want to push back to the repository where build is running. This can be confirmed in the Build Setup phase, which contains the following entry :
git config http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy http://localhost:29418/
And also if you run the command :
git config --list
Which, among other settings, should show a line similar to this :
[...]
http.http://bitbucket.org/WORKSPACE/REPOSITORY_SLUG.proxy=http://localhost:29418/
[...]
This is essentially saying to git that any request going to that URL will be redirected to the internal proxy.
The internal proxy is accessible from the Build container, where your script runs. Pipes run in a separate docker container, and the pipe container is not able to access the address http://localhost:29418, causing the connection failure returned in the logs.
ソリューション
Since the internal proxy is not accessible from within the pipe, you can unset the proxy as part of your pipes script, with the following command :
git config --unset http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy
This should remove the proxy config of your git environment in the build.
Please note that, as we don't have the proxy to handle the authentication now, you will need to set it manually as part of your code. The command depends on whether you want to use HTTPS or SSH, and needs to be executed as part of your pipe's script:
- For HTTPS
git remote set-url origin https://$BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD@bitbucket.org/$BITBUCKET_REPO_FULL_NAME
- For SSH
git remote set-url origin git@bitbucket.org/$BITBUCKET_REPO_FULL_NAME