1

So I cache my python dependencies during my pipeline build as described here: https://medium.com/@andre.gensler/guide-how-to-speed-up-your-python-continuous-integration-pipeline-in-azure-devops-using-dependency-916d9cd792a0

And then I want pulumi to use this environment. It is activated but not within task Pulumi@1.

Does someone have a working solution to get Pulumi to activate the environment?

When I run pulumi preview as task with Pulumi@1.

azure-pipelines.yml

trigger:
  - feature/12345

variables:
  - name: vmImageName
    value: 'ubuntu-latest'
  - name: CONDA_ENV_NAME
    value: "venv"
  - name: CONDA_ENV_DIR
    value: $(CONDA)/envs/$(CONDA_ENV_NAME)

pool:
  vmImage: $(vmImageName)

stages:
 - stage: Pulumi_Preview_Roles
    displayName: "Pulumi (Preview)"
    jobs:
    - job: CondaPulumiTest
      steps:
      
      - script: echo "##vso[task.prependpath]$CONDA/bin"
        displayName: Add conda to PATH
        
      - task: Cache@2
        displayName: Use cached Anaconda environment
        inputs:
          key: 'conda | "$(Agent.OS)" | requirements.txt'
          path: $(CONDA_ENV_DIR)
          cacheHitVar: CONDA_CACHE_RESTORED

      - bash: conda create --yes --quiet --name $(CONDA_ENV_NAME)
        displayName: Create Anaconda environment
        condition: eq(variables.CONDA_CACHE_RESTORED, 'false')
        
      - bash: |
          source activate $(CONDA_ENV_NAME)
          pip install -r requirements.txt
        displayName: Install dependencies
        condition: eq(variables.CONDA_CACHE_RESTORED, 'false')


      - task: Pulumi@1
        inputs:
          azureSubscription: 'Something'
          command: 'preview'
          args: '--diff --show-config --show-reads --show-replacement-steps'
          stack: $(pulumiStackShort)
          cwd: "./"
        env:
          AZURE_CLIENT_ID_: $(AZURE_CLIENT_ID)
          AZURE_CLIENT_SECRET_: $(AZURE_CLIENT_SECRET)
          AZURE_TENANT_ID_: $(AZURE_TENANT_ID)
          CONDA_ENV_DIR_: $(CONDA_ENV_NAME) 

I then get the following error message:


ModuleNotFoundError: No module named 'pulumi'

It looks like the Pulumi SDK has not been installed. Have you run pip install?

If you are running in a virtualenv, you must run pip install -r requirements.txt from inside the virtualenv.

I have tried to set the environment in Pulumi.yaml:

name: AlertRulesPulumi
description: A minimal Azure Native Python Pulumi program
runtime:
    name: python
    options:
        virtualenv: $(CONDA)/envs/$(CONDA_ENV_NAME)

0 Answers0