0

我正在尝试创建一个计划的 Azure 管道,在其中我使用服务连接克隆一个自托管的 BitBucket git 存储库并将其镜像到现有的 Azure git 存储库。

客户端在他们自己的 BitBucket 服务器上保留一个代码存储库。我想设置一个管道,在其中按计划的时间间隔从该存储库中提取任何更改到我自己的 Azure 存储库中,以便我可以设置自动部署。

我一直在挂断服务连接部分的事情。服务连接设置为“其他 Git”,并包含访问远程 BitBucket 服务器所需的所有凭据。

trigger: none

schedules:
- cron: "*/30 * * * *" # RUN EVERY 30 MINUTES
  displayName: Scheduled Build
  branches:
    include:
    - my-branch
  always: true # RUNS ALWAYS REGARDLESS OF CHANGES MADE

pool:
  name: Azure Pipelines

steps:
- task: AzureCLI@2
  name: setVariables
  displayName: Set Output Variables
  continueOnError: false
  inputs:
    azureSubscription: "Service Connection Name"
    scriptType: ps
    scriptLocation: inlineScript
    addSpnToEnvironment: true
    inlineScript: | 
      Write-Host "##vso[task.setvariable variable=username;isOutput=true]$($env:username)"
      Write-Host "##vso[task.setvariable variable=password;isOutput=true]$($env:password)"

- powershell: |
   # Use the variables from above to pull latest from
   # BitBucket then change the remote origin and push
   # everything to my Azure repo
  displayName: 'PowerShell Script'

当我运行它时,我最终收到一条错误消息:

The pipeline is not valid. Job: setVariables input connectedServiceNameARM 
expects a service connection of type AzureRM but the proviced service connection is of type git.

如何从我的 YAML 管道中的 git 服务连接访问变量?

4

1 回答 1

0

AzureCLI 任务仅接受 Azure 资源管理器类型的服务连接。所以你使用的 git 连接不起作用。

根据您的需要,您可以先查看 repo。Bitbucket 存储库有一个Bitbucket 云服务连接。如果您将 yaml 文件保存在 azure存储库中,则可以使用它来检查管道中的多个存储库。

这是示例 yaml 和屏幕截图:

resources:
  repositories:
  - repository: MyBitbucketRepo
    type: bitbucket
    endpoint: MyBitbucketServiceConnection
    name: MyBitbucketOrgOrUser/MyBitbucketRepo

trigger: none


schedules:
- cron: "*/30 * * * *" # RUN EVERY 30 MINUTES
  displayName: Scheduled Build
  branches:
    include:
    - my-branch
  always: true # RUNS ALWAYS REGARDLESS OF CHANGES MADE

pool:
  name: Azure Pipelines

steps:
- checkout: MyBitbucketRepo

- powershell: |
   # Use the variables from above to pull latest from
   # BitBucket then change the remote origin and push
   # everything to my Azure repo
  displayName: 'PowerShell Script'

在此处输入图像描述

于 2022-03-04T03:03:57.163 回答