skip to Main Content

I want to define the PATH only once for the whole pipeline.

Is this possible?

I’ve done this, but it doesn’t work:

trigger:
  - master

jobs:
  - job: Application
    pool:
      vmImage: ubuntu-latest
    steps:
      - task: CmdLine@2
        displayName: "Install flutter"
        inputs:
          workingDirectory: $(Agent.ToolsDirectory)
          script: |
            git clone https://github.com/flutter/flutter.git -b stable --depth 1
            export PATH="$PATH:`pwd`/flutter/bin"
            echo "##vso[task.setvariable variable=path;isOutput=true]$PATH"
            flutter config --no-analytics
            yes | flutter doctor --android-licenses
      - task: CmdLine@2
        displayName: "flutter get"
        inputs:
          script: |
            flutter pub get

2

Answers


  1. Chosen as BEST ANSWER

    The solution is to add the BASH_ENV: "~/.profile" variable and put path in ~/.profile.

    trigger:
      - master
    
    variables:
      BASH_ENV: "~/.profile"
    
    jobs:
      - job: Application
        pool:
          vmImage: ubuntu-latest
        steps:
          - task: CmdLine@2
            inputs:
              workingDirectory: $(Agent.ToolsDirectory)
              script: |
                git clone https://github.com/flutter/flutter.git -b stable --depth 1
                echo "export PATH=$PATH:`pwd`/flutter/bin" >> ~/.profile
                source ~/.profile
          - task: CmdLine@2
            inputs:
              script: |
                flutter config --no-analytics
    

  2. I think this is basically a Linux issue.

    See the Ubuntu official document:

    https://help.ubuntu.com/community/EnvironmentVariables#System-wide_environment_variables

    Process locality:
    The values of environment variables are local, which
    means they are specific to the running process in or for which they
    were set. This means that if we open two terminal windows (which means
    we have two separate bash processes running), and change a value of an
    environment variable in one of the windows, that change will not be
    seen by the shell in the other window or any other program currently
    on the desktop.

    This is why the variable not been passed, it only lives in the first terminal.

    Please check the system wide environment variables in the documents. I think you need to change something in the machine (edit some files or add some files).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search