0
votes

Is it possible to setup multiple steps and download a container from previous step, so you don't have to build the container again?

Current scenario:

steps

So in a publish step, I only want to upload the pre-built container from the build step, so I can upload the relevant container registry.

Why? Because the pipeline triggers during a pull request, even when the triggers are set like:

trigger:
- master
- release/*

I imagine something like this:

jobs:
  - job: build_and_tests
    steps:
      - script: docker build --no-cache -t {...}
        displayName: 'Building dockerfile'
    ...
    ...
    ...
    # upload docker **container** to artifacts?

  - job: build_and_publish
    dependsOn: build_and_tests
    condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')) )
    steps:
    #  - download: download the docker **container** from previous job step?

      - script: docker login -u $(registryUser) -p $(registryPassword) $(registryName)
        displayName: 'Login to ACR'
     ...
     ...
     ...

The # marks my imagination :) Any ideas?

1
You could push the image to ACR, and then pull it during the next job, or you could put it in artifactory, but I would not. Why not just put the steps in the same job, they will be run sequentially anyway because of the DependsOn. But if you want to, then you could use caching and then build the image again in the second job, with caching: docs.microsoft.com/en-us/azure/devops/pipelines/release/…Bo Søborg Petersen

1 Answers

2
votes

upload dockerfile to artifacts? download: download the dockerfile from previous job step?

According to the description, if only these two imaginations are realized, you can add copy file task and Publish build artifacts task to the first job to upload the dockerfile to artifact. Then download the dockerfile via Download build artifacts task in the second job.

Here are the references to these tasks: