Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Azure DevOps: Installations dissapear between stages

We use stages in Azure DevOps, as it is possible to select which stages, you want to run when running a pipeline (see picture). An annoying thing when running stages, however, is that if you install a program in Stage 1, it seems that you cannot use that program in Stage 2.

Is there a way to install a program just once, and then have it available in all stages?

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here an example of what I would like to do: 1) Install kubectl in Stage 1, 2) Use kubectl in Stage 2.

trigger:
- master

pool:
  vmImage: ubuntu-22.04

steps:
- stage: MakeK8sConfiguration
  jobs:
  - job: MakeK8sConfiguration
    steps:
      - script: |
          # Downloading kubectl
          curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
          
          # Installing kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

- stage: MakeK8sDeployment
  jobs:
  - job: MakeK8sDeployment
    steps:
      - script: |
        # Running kubectl
        kubectl

>Solution :

From your YAML file, you are using Microsoft-Hosted agent:ubuntu-22.04.

Refer to this doc: Microsoft-hosted agents

Each time you run a pipeline, you get a fresh virtual machine for each job in the pipeline. The virtual machine is discarded after one job (which means any change that a job makes to the virtual machine file system, such as checking out code, will be unavailable to the next job).

In your situation, different stages will use different and new Microsoft-hosted agents. They are independent.

So when you install the kubectl at first stage, the second stage still not able to use the kubectl.You still need add additional steps to install kubectl in stage two.

Is there a way to install a program just once, and then have it available in all stages?

Based on your requirement, I suggest that you can use Self-hosted agent or VMSS agent to run the pipeline. They can keep the pipeline stages running on the same agent machine.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading