How to set PATH in Jenkins Declarative Pipeline

后端 未结 4 803
面向向阳花
面向向阳花 2021-01-01 08:55

In Jenkins scripted pipeline you can set PATH env variable like this :

node {
   git url: \'https://github.com/jglick/simple-maven-project-with-tests.git\'
          


        
相关标签:
4条回答
  • 2021-01-01 09:22

    It is possible with environment section:

    pipeline {
      agent { label 'docker' }
      environment {
        PATH = "/hot/new/bin:$PATH"
      }
      stages {
        stage ('build') {
          steps {
            echo "PATH is: $PATH"
          }
        }
      }
    }
    

    See this answer for info.

    0 讨论(0)
  • 2021-01-01 09:22

    As a workaround, you can define an environment variable and use it in the sh step:

    pipeline {
        environment {
            MAVEN_HOME = tool('M3')
        }
    
        stages {
            stage(Maven') {
               sh '${MAVEN_HOME}/bin/mvn -B verify'
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-01 09:31

    Check the following link, this explains how to configure your tools. Using the declarative pipeline things become a bit different but overall it is easier to understand.

    declarative-maven-project

    0 讨论(0)
  • 2021-01-01 09:32

    Using the tool section in pipeline is only allowed for pre-installed Global Tools. Some tools are provided by plugins, but if it not exists I'am afraid you cannot use the environment setup via pipeline tool declaration.

    I hope to be wrong!

    0 讨论(0)
提交回复
热议问题