sh 通过API向BitBucket添加新的部署密钥

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 通过API向BitBucket添加新的部署密钥相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash
set -e

KEY=public-key
LABEL=key123

###
# Method 1. Authenticate by your account & password
###
AUTH=user:password

curl -X POST --user $AUTH \
  https://api.bitbucket.org/1.0/repositories/plaxieappier/cmpboard/deploy-keys \
  --data "key=$KEY&label=$LABEL"

###  
# Method 2. Authenticate by OAuth2 (Google)
#
# ref. https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html#OAuthonBitbucketCloud-OAuth2.0
###

CLIENT_ID=client-id # As well as "Key" in OAuth consumers
SECRET=secret

# Step 1. Go to following URL to get the "code"
# https://bitbucket.org/site/oauth2/authorize?client_id=$CLIENT_ID&response_type=code
# Then, Copy the "code" value from URL query string
$CODE=from-browser-url

# Step 2. Get the access token
curl -X POST -u "$CLIENT_ID:$SECRET" \
  https://bitbucket.org/site/oauth2/access_token \
  -d grant_type=authorization_code -d code=$CODE
# API will returns an JSON object including "access_token", for example:
# {
#   "access_token": "...Z3O1OXk...",
#   "scopes": "repository:write",
#   "expires_in": 3600,
#   "refresh_token": "...ySRtPV...",
#   "token_type": "bearer"
# }
ACCESS_TOKEN=from-step2-response

# Step 3. Request API with access token
curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
  https://api.bitbucket.org/1.0/repositories/plaxieappier/cmpboard/deploy-keys \
  --data "key=$KEY&label=$LABEL"

以上是关于sh 通过API向BitBucket添加新的部署密钥的主要内容,如果未能解决你的问题,请参考以下文章

使用 Bitbucket Pipelines 从 docker 实例 SSH 到登台机器

sh 如何将远程仓库添加到bitbucket

sh Bitbucket Cloud - 将现有的无版本代码添加到空存储库

OpsWorks 中的部署问题

markdown 通过Webhook进行代码部署(Bitbucket)

使用 BitBucket Pipelines 通过 SSH 访问部署到 VPS