Codebuild path env var not updating when using windows image (windows-base:2019-2.0 using powershell)

0

PATH environment variable not updating in AWS CodeBuild when using windows-base:2019-2.0 with powershell.

When installing cargo with rustup (or any software as far as I can tell) it fails to update the PATH environment variable on the windows image with powershell. Things I've tried:

  • Waiting til next build step
  • Loading local path from System Environment ($env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") )
  • Setting path manually after rustup install ($env:PATH += ";${env:USERPROFILE}\cargo\.bin")

env:path before, after and during build will be identical to one another in this example and the expected commands (cargo in this case) will not work in the build step.

Found no workaround for this (other than maybe hardcoding the entire path along with the expected values in variables section but this is obviously not a good idea)

version: 0.2

env:
  shell: powershell.exe 
phases:
  install:
    commands:
      - Write-Host "env:Path before..."
      - Write-Host "$env:Path"
      - Write-Host "Installing required tools..."
      - Invoke-WebRequest -Uri https://win.rustup.rs/ -OutFile rustup-init.exe
      - ./rustup-init.exe -y
      - Write-Host "env:Path after"
      - Write-Host "$env:Path"
  pre_build:
    commands:
      - Write-Host "Running pre-build commands..."
  build:
    commands:
      - Write-Host "env:Path during build"
      - Write-Host "$env:Path"
      - cargo -V
kb
demandé il y a 8 mois122 vues
1 réponse
0

I found that this is caused by a behavior of CodeBuild when running on Windows. The behavior is that Codebuild invokes a brand new process for every line that starts with '-' in the buildspec.

This appears to be an undocumented defect in codebuild that was confirmed by an AWS support engineer.

Your updated buildspec would be:

version: 0.2

env:
  shell: powershell.exe 
phases:
  build:
    commands:
      - |
        Write-Host "env:Path before..."
        Write-Host "$env:Path"
        Write-Host "Installing required tools..."
        Invoke-WebRequest -Uri https://win.rustup.rs/ -OutFile rustup-init.exe
        ./rustup-init.exe -y
        Write-Host "env:Path after"
        Write-Host "$env:Path"
        cargo -V
répondu il y a un mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions