出口指令在詹金斯管道 [英] Export command in Jenkins pipeline

查看:206
本文介绍了出口指令在詹金斯管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Jenkins管道中添加exportunix命令?
我有一个詹金斯的舞台和'台阶'。导出命令的语法是什么我需要使用export命令设置环境变量'PATH'。

解决方案

您可以像这样更新 $ PATH >

  pipeline {
agent {label'docker'}
stages {
stage('build') {
steps {

// JENKINSHOME只是一个名字来帮助可读性
withEnv(['PATH + JENKINSHOME = / home / jenkins / bin']){
echoPATH is:$ PATH
}
}
}
}
}

当我运行这个结果是:

  [管道] echo 
PATH是:/ home / jenkins / bin:/ usr / local / sbin:/ usr / local / bin:/ usr / sbin:/ usr / bin:/ sbin:/ bin:/ usr / games:/ usr / local / games

这是什么? PATH + JENKINSHOME 语法?从在designhammer.com的博客引用:



这样:

  / my / additional / path:$ PATH 

表示为:

  PATH + ANYSTRING = /我/额外/路径。 

ANYSTRING 只是一个名字来帮助可读性。如果它不能帮助可读性,在你看来,你可以省略它。所以这是相当的:

  PATH + = / my / additional / path 
pre>

以上( withEnv )允许您更新$ $ $ $ $ $ $ $ $ $ $ code>为管道的特定部分。要更新整个管道的 $ PATH ,您不能使用 PATH + ANYSTRING 语法,但这可以:

  pipeline {
agent {label'docker'}
environment {
PATH = / hot / new / bin:$ PATH
}
阶段{
stage('build'){
steps {
echoPATH is:$ PATH
}
}
}
}

生成输出:

  [Pipeline] echo 
PATH是:/ hot / new / bin:/ usr / local / sbin:/ usr / local / bin:/ usr / sbin:/ usr / bin:/ sbin:/ bin:/ usr / games:/ usr / local / games


How to add an 'export' unix command in a Jenkins pipeline? I have a Jenkins 'stage' and 'steps' within it. What is the syntax for an export command. I need to set the environment variable 'PATH' using the export command.

解决方案

You can update the $PATH like this:

pipeline {
  agent { label 'docker' }
  stages {
    stage ('build') {
      steps {

        // JENKINSHOME is just a name to help readability
        withEnv(['PATH+JENKINSHOME=/home/jenkins/bin']) {
          echo "PATH is: $PATH"
        }
      }
    }
  }
}

When I run this the result is:

[Pipeline] echo
PATH is: /home/jenkins/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

What the heck is this PATH+JENKINSHOME syntax? Quoting from a blog at designhammer.com:

This:

/my/additional/path:$PATH

is expressed as:

PATH+ANYSTRING=/my/additional/path.

ANYSTRING is just a name to help readability. If it doesn't help readability, in your view, you can omit it. So this is equivalent:

PATH+=/my/additional/path

The above (withEnv) allows you to update the $PATH for a specific part of your pipeline. To update the $PATH for the entire pipeline, you can't use the PATH+ANYSTRING syntax, but this works:

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

Produces output:

[Pipeline] echo
PATH is: /hot/new/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

这篇关于出口指令在詹金斯管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆