How to set PATH in Jenkins Declarative Pipeline

*爱你&永不变心* 提交于 2019-11-30 10:57: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.

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'
        }
    }
}

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

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!