在azure管道上获得类似意外值“name”的错误

3qpi33ja  于 2023-02-05  发布在  其他
关注(0)|答案(1)|浏览(140)

我有下面的yaml文件。我正在尝试解决两个部署文件设置在两个不同的管道存在于一个文件夹中的问题,以及一个文件更改不触发其他管道基于文件更改的情况。
出于上述目的,我进行了以下更改,但在管道中出现错误意外值“name”
代码如下

.....
trigger:
  paths:
    include:
      - '.devops/**'

variables:
  deploymentFile: 'test-hub-deploy-dev.yml'

stages:
  - stage: Get the deployment file name
    jobs:
      - job: Get deployment file
        displayName: 'Get deployment file'
        steps:
          - name: Get the deployment file name    // getting error at here 
            script: |
              if [[ $Build.SourcesDirectory == *"deployment-folder"* ]]; then
                echo "##[set-output name=deploymentFile;]$(basename $Build.SourcesDirectory)"
              fi
            displayName: Get deployment file name
            env:
              SYSTEM_DEFAULTWORKINGDIRECTORY: $(System.DefaultWorkingDirectory)
              BUILD_SOURCESDIRECTORY: $(Build.SourcesDirectory)
            outputs:
              deploymentFile: '$(deploymentFile)'

          - name: Deploy to test-dev
            condition: and(succeeded(), eq(variables['deploymentFile'], 'test-hub-deploy-dev.yml'))
            script: echo "Deploying using test-hub-deploy-dev.yml"
            displayName: Deploy to test-dev

  - stage: Build
    jobs:
    ....

我不知道上面的yaml代码哪里做错了,请给我指出正确的方向。

ddrv8njm

ddrv8njm1#

1 - In触发器节“include”和-“.devops/**”应位于同一标识级别https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/trigger?view=azure-pipelines#examples-2

trigger:
  paths:
    include:
    - '.devops/**'

2 -“stages”和“- stage”相同:abc'
https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/stages-stage?view=azure-pipelines

stages:
- stage: abc

3 -对于“作业”和“-作业”相同https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/jobs?view=azure-pipelines#examples
4 -对于“步骤”https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps?view=azure-pipelines
首先声明您的步骤(script/pwsh/other),然后您可以为其指定名称。“script”前面需要有破折号。https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-script?view=azure-pipelines#examples
5 -输出变量用于从下一个作业获取此变量时,这里是第二步,使用同一作业中第一步的变量。
6 -您是在哪里找到这个“set-output”的?为什么不使用##vso + task. setvariable呢?这整行都无法正常工作。
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash#set-an-output-variable-for-use-in-the-same-job
7 - $(basename $Build.SourcesDirectory)我假设“basename”是变量,而不是常量字符串,但您没有提供此信息。这将永远不会起作用,要访问变量,您需要使用语法$(VariableName)如果要将变量连接起来,请将它们放在一起“$(basename)$(Build.SourcesDirectory)
8 -我不保证它会完全工作因为有很多错误,我可能会错过一些东西。
yaml的“steps”部分应该与此类似

steps:
        - script: |
            if [[ $Build.SourcesDirectory == *"deployment-folder"* ]]; then
              echo "##vso[task.setvariable variable=deploymentFile;]$(basename)$(Build.SourcesDirectory)"
            fi
          name: Get the deployment file name
          displayName: Get deployment file name
          env:
            SYSTEM_DEFAULTWORKINGDIRECTORY: $(System.DefaultWorkingDirectory)
            BUILD_SOURCESDIRECTORY: $(Build.SourcesDirectory)
        - script: echo "Deploying using test-hub-deploy-dev.yml"
          displayName: Deploy to test-dev
          name: Deploy to test-dev
          condition: and(succeeded(), eq(variables['deploymentFile'], 'test-hub-deploy-dev.yml'))

相关问题