How to write/push commits to a repository from a Windows runner?

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Cloud のみ - この記事は、 クラウド プラットフォームのアトラシアン製品にのみ適用されます。

要約

This article covers the steps including commands on how to push back to your repository from Windows runner using PowerShell.

ソリューション

You can follow the below steps while using OAuth consumer keys to push back to your repository.

OAuth:

Note: When using OAuth with branch permissions, you'll need to have an existing account, create an account or bot account and give that account write access in the branch permission to allow pushing directly to your main branch.


  1. In Bitbucket, click your avatar choose a workspace, and select Settings > OAuth consumers > Add consumer.

  2. 新しいクライアント/コンシューマーを作成し、自身のアカウントのリポジトリへの読み取りおよび書き込み権限を付与します。

  3. Provide a name, optional description, and set the callback URL to https://bitbucket.org.

  4. Select the This is a private consumer checkbox.

  5. Under Permissions > Repositories, tick both Read and Write.

  6. [保存] をクリックします。

  7. 新しく作成されたコンシューマーに移動してキーを記録します。

  8. Add the keys as pipeline variables with the names CLIENT_ID and CLIENT_SECRET.

  9. Add the following to the script section in your bitbucket-pipelines.yml file.


bitbucket-pipelines.yml
script:
	- $body = @{ "grant_type" = "client_credentials" }
	- $params = @{ Uri = 'https://bitbucket.org/site/oauth2/access_token' ; Method = 'Post' ; Body = $body ; Headers = @{ Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($env:CLIENT_ID):$($env:CLIENT_SECRET)")) } }
                
	- $response = Invoke-RestMethod @params
	- $token = $response.access_token
	- git remote set-url origin "https://x-token-auth:$token@bitbucket.org/$env:BITBUCKET_REPO_OWNER/$env:BITBUCKET_REPO_SLUG"
	- git remote -v
	- echo "Made a change in build ${BITBUCKET_BUILD_NUMBER}" >> changes.txt
	- git add changes.txt
	- git commit -m "[skip ci] Updating changes.txt with latest build number."
	- git push 

最終更新日: 2024 年 1 月 2 日

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

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