0

在我的 CircleCI 脚本中,我有几个作业正在执行一个使用一些环境变量和一些静态参数的 PowerShell 脚本。

jobs:
  promote_to_staging:
    docker:
      - image: mcr.microsoft.com/powershell
    steps:
      - run:
          name: Install tools
          shell: pwsh
          command: |
            Install-Module -Name AWS.Tools.Installer -Force
            Install-AWSToolsModule AWS.Tools.ECR -Force -CleanUp
      - run:
          name: Tag images
          shell: pwsh
          command: |
            Set-DefaultAWSRegion -Region $env:AWS_DEFAULT_REGION
            foreach ($repo in Get-ECRRepository)
            {
                $Image = Get-ECRImageBatch -ImageId @{ imageTag = $env:CIRCLE_SHA1 } -RepositoryName $repo.RepositoryName
                $Manifest = $Image.Images[0].ImageManifest
                Write-ECRImage -RepositoryName $repo.RepositoryName -ImageManifest $Manifest -ImageTag "staging" | Out-Null
                Write-ECRImage -RepositoryName $repo.RepositoryName -ImageManifest $Manifest -ImageTag $env:CIRCLE_TAG | Out-Null
            }

一切都按预期工作。

为了 DRYfy 脚本,我决定在一个球体的参数化作业中提取所述作业。

orbs:
  services:
    jobs:
      promote:
        docker:
          - image: mcr.microsoft.com/powershell
        parameters:
          stage_tag:
            type: string
        steps:
          - run:
              name: Install tools
              shell: pwsh
              command: |
                Install-Module -Name AWS.Tools.Installer -Force
                Install-AWSToolsModule AWS.Tools.ECR -Force -CleanUp
          - run:
              name: Tag images
              shell: pwsh
              command: |
                Set-DefaultAWSRegion -Region $env:AWS_DEFAULT_REGION
                foreach ($repo in Get-ECRRepository)
                {
                    $Image = Get-ECRImageBatch -ImageId @{ imageTag = $env:CIRCLE_SHA1 } -RepositoryName $repo.RepositoryName
                    $Manifest = $Image.Images[0].ImageManifest
                    Write-ECRImage -RepositoryName $repo.RepositoryName -ImageManifest $Manifest -ImageTag "<< parameters.stage_tag >>" | Out-Null
                    Write-ECRImage -RepositoryName $repo.RepositoryName -ImageManifest $Manifest -ImageTag $env:CIRCLE_TAG | Out-Null
                }    

这就是我在球体中消费工作的方式

  release:
    jobs:
      - services/promote:
          name: promote_to_staging
          stage_tag: staging
          context:
            - AWS_CI
          filters:
            branches:
              ignore: /.*/
            tags:
              only: <<omitted for brevity>>
            

不幸的是,orb 作业没有按预期工作。

这是我得到的输出:

#!pwsh
Set-DefaultAWSRegion -Region $env:AWS_DEFAULT_REGION
foreach ($repo in Get-ECRRepository)
{
    $Image = Get-ECRImageBatch -ImageId @{ imageTag = $env:CIRCLE_SHA1 } -RepositoryName $repo.RepositoryName
    $Manifest = $Image.Images[0].ImageManifest

    Write-ECRImage -RepositoryName $repo.RepositoryName -ImageManifest $Manifest -ImageTag "staging" | Out-Null
    Write-ECRImage -RepositoryName $repo.RepositoryName -ImageManifest $Manifest -ImageTag $env:CIRCLE_TAG | Out-Null
}        

WARNING: You are passing $null as a value for parameter ImageManifest which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.
Write-ECRImage: 
Line |
   7 |      Write-ECRImage -RepositoryName $repo.RepositoryName -ImageManifes …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Invalid parameter at 'imageManifest' failed to satisfy constraint: 'Member must not be null'
WARNING: You are passing $null as a value for parameter ImageManifest which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.
Write-ECRImage: 
Line |
   8 |      Write-ECRImage -RepositoryName $repo.RepositoryName -ImageManifes …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Invalid parameter at 'imageManifest' failed to satisfy constraint: 'Member must not be null'
WARNING: You are passing $null as a value for parameter ImageManifest which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.

我已经尝试替换$env:CIRCLE_SHA1$CIRCLE_SHA1${CIRCLE_SHA1}没有帮助。

欢迎任何帮助!

4

0 回答 0