如何使用AzureDevops中的工件来构建从一项作业到另一项作业的管道

时间:2020-04-18 17:28:00

标签: azure-devops

我创建了一个构建管道,其中

在Job1中:我在python容器中创建了一个特定文件 在Job2中:我想将该文件用于下一个要在Docker Container中使用的进程

为此,我为Job1创建了一个名为configCreate的工件,在job2中,我试图下载以上在$(System.DefaultWorkingDirectory)中创建的工件。但是,当我尝试访问文件时,仍然看到源文件而不是Job1文件。如何从Job1工件访问Job2工件? Reference

所以

 stages:
    - stage: Build
      displayName: BUILD NON MASTER BRANCH
      condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master'))

      variables:
      - group: Common_DEV

      jobs:
      - job: buildConfig
        displayName: 'Create Properties file.'
        container: python3
        pool: rhel

        steps:
          - bash: echo "Hello World!!! - $(Build.SourceBranch)"
            displayName: "Started building for $(Build.SourceBranch)"
          - bash: |
              echo PythonV3
              python3 -m venv venv
              source venv/bin/activate
              python --version
              pip3 install -r $(System.DefaultWorkingDirectory)/requirements.txt
              python3 injectConfigProperties.py
              echo "Finish creating the Properties."
              deactivate
              rm -r venv/
              cat $(System.DefaultWorkingDirectory)/properties/config.properties
            displayName: Build Config file 
        - task: CopyFiles@2
            inputs:
              contents: |
                $(System.DefaultWorkingDirectory)
              targetFolder: $(Build.ArtifactStagingDirectory)
          - task: PublishBuildArtifacts@1
            inputs:
              pathtoPublish: $(Build.ArtifactStagingDirectory)
              artifactName: configCreate

        - job: Job2
            displayName: 'JOb2'
            container: docker
            pool: rhel

            dependsOn:
            - buildConfig
            condition: succeeded()

            steps:
              - task: DownloadBuildArtifacts@0
                displayName: 'Download Build Artifacts from buildConfig.'
                inputs:
                  artifactName: configCreate
                  downloadPath: $(System.DefaultWorkingDirectory)

         - bash: |
                  cat $(System.DefaultWorkingDirectory)/properties/config.properties
                  ls -ltr $(System.DefaultWorkingDirectory)/pipelines/
                displayName: 'Build Docker Image'

1 个答案:

答案 0 :(得分:0)

在job2中用于访问工件的是cat $(System.DefaultWorkingDirectory)/artifactName/properties/config.properties

我错过了工件的名称,以访问工件。现在已修复。