Home > OS >  How to reuse DownloadFile from a task in another task Azure Pipeline
How to reuse DownloadFile from a task in another task Azure Pipeline

Time:05-20

I would like to avoid repeating code in Pipeline on Azure DevOps. For one task I need to download the settings and at the last step, I also need to reuse this file. I tried to access this variable, but it returned "It was impossible to find this variable".

stages:
    - stage: Setup
      jobs:
        - job: Verify
          steps:
            - task: DownloadSecureFile@1
              name: mvnSettings
              displayName: 'Download maven settings'
              inputs:
                secureFile: 'settings-azure.xml'

            - task: Maven@3
              inputs:
                mavenPomFile: 'pom.xml'
                options: '-s $(mvnSettings.secureFilePath)' ...

    - stage: build_and_deploy
      jobs:
        - job: build_and_deploy
          steps:
            - task: DownloadSecureFile@1
              name: mvnSettings
              displayName: 'Download maven settings'
              inputs:
                secureFile: 'settings-azure.xml'
            - task: Maven@3 ...

The goal is to reuse the variable created in this block below.

        - task: DownloadSecureFile@1
          name: mvnSettings
          displayName: 'Download maven settings'
          inputs:
            secureFile: 'settings-azure.xml'

CodePudding user response:

If you change job, you change Build Agent. This is why your file is lost.

You can use artifact to pass files from job to jobs or task to task.

You will find how to do here:

https://docs.microsoft.com/en-us/azure/devops/pipelines/artifacts/build-artifacts?view=azure-devops&tabs=yaml

Be carefull. There are build artifact that are deprecated. Use pipeline artifact instead

  • Related