我应该将任务放在 yaml 文件中的什么位置?

where do i put task in the yaml file?

在下面的 yaml 中插入 -task 时,我总是出错...我做错了什么??

pool:
  vmImage: ubuntu-latest

variables:
  - group: variables

**- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.
      
      Write-Host "pullrequest"
      Write-Host "PR Number is:-" $(System.PullRequest.PullRequestId)"
      Write-Host "PR Number is:-" $(System.PullRequest.PullRequestNumber)"**

  # Login to DockerHub
  - script: docker login -u $(dockerId) -p $pass
    env:
      pass: $(dockerPassword)
    displayName: Login to DockerHub

  # Build and run tests
  - script: |
      docker pull $(dockerRegistry)/$(dockerImageName):cache-test-dependencies || true
      docker pull $(dockerRegistry)/$(dockerImageName):cache-test || true

      docker-compose --file=docker-compose.test.yml build
    displayName: Build test Docker image
    continueOnError: false

task 必须是 steps

的成员

参考文档在这里; https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-task?view=azure-pipelines.

添加

steps:

在你的任务之前。

要详细说明,另外您很可能需要这方面的阶段和工作:

pool:
vmImage: ubuntu-latest

variables:
  - group: variables
stages:
- stage: Build_Stage
    jobs:
    - job: Build_Job
        steps:
        - task: PowerShell@2
          inputs:
            targetType: 'inline'
            script: |
              # Write your PowerShell commands here.
              
              Write-Host "pullrequest"
              Write-Host "PR Number is:-" $(System.PullRequest.PullRequestId)"
              Write-Host "PR Number is:-" $(System.PullRequest.PullRequestNumber)"**
        
        # Login to DockerHub
        - script: docker login -u $(dockerId) -p $pass
        env:
          pass: $(dockerPassword)
        displayName: Login to DockerHub

        # Build and run tests
        - script: |
          docker pull $(dockerRegistry)/$(dockerImageName):cache-test-dependencies || true
          docker pull $(dockerRegistry)/$(dockerImageName):cache-test || true

          docker-compose --file=docker-compose.test.yml build
        displayName: Build test Docker image
        continueOnError: false

Stages will set you up to tie to environments, meanwhile jobs will set you up to take advantage of parrellelism if running multiple jobs.