0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Automation の PAT 連携を Azure CLI でやってみた

Posted at

以前、下記の記事を書きました。

今回は、Azure Automation のソース管理と同期ジョブ設定で Azure Repos との PAT 連携を Azure CLI でやってみました。

PAT 作成

こちらのドキュメント通りに、最小限のアクセス許可を付与した PAT を作成します。

Scope アクセスの種類
Code Read
Project and team Read
Identity Read
User profile Read
Work items Read
Service connections 読み取り、クエリの実行、および管理

ソース管理と同期ジョブを設定

bash
# 環境変数をセット
prefix=mnrauto
pat=your_pat_here
commitid=$(git log --pretty=format:"%H" -1)

# ソース管理を設定
az rest \
  --method put \
  --url "$(az automation account show \
  --automation-account-name ${prefix} \
  --resource-group ${prefix}-rg \
  --query id \
  --output tsv)/sourceControls/${prefix}?api-version=2019-06-01" \
  --body '{
    "properties": {
      "repoUrl": "https://mnrsdev@dev.azure.com/mnrsdev/mnrsdev/_git/'${prefix}'",
      "branch": "main",
      "folderPath": "/",
      "autoSync": true,
      "publishRunbook": true,
      "sourceType": "VsoGit",
      "securityToken": {
        "accessToken": "'$pat'",
        "tokenType": "PersonalAccessToken"
      },
      "description": ""
    }
  }'

# 同期ジョブを設定
az rest \
  --method put \
  --url "$(az automation account show \
  --automation-account-name ${prefix} \
  --resource-group ${prefix}-rg \
  --query id \
  --output tsv)/sourceControls/${prefix}/sourceControlSyncJobs/$(uuidgen)?api-version=2019-06-01" \
  --body '{
    "properties": {
      "commitId": "'$commitid'"
    }
  }'

# 同期ジョブの状態を確認
az rest \
  --method get \
  --url "$(az automation account show \
  --automation-account-name ${prefix} \
  --resource-group ${prefix}-rg \
  --query id \
  --output tsv)/sourceControls/${prefix}/sourceControlSyncJobs?api-version=2019-06-01"

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?