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
    This considers you have variables provided either in the pipe config in the YML file or in your workspace/repository variables with $BITBUCKET_USERNAME and $BITBUCKET_APP_PASSWORD. The $BITBUCKET_REPO_FULL_NAME is already a default variable provided by bitbucket that contains the workspace/repo_slug.
  • For SSH
    git remote set-url origin git@bitbucket.org/$BITBUCKET_REPO_FULL_NAME
    This will by default use the SSH key configured in Repository Settings > SSH Keys (under Pipelines section), unless you have a different ssh key configured as part of your pipe's container.


最終更新日: 2025 年 1 月 17 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.