Jenkins没有看到GIT环境变量

时间:2017-02-13 17:13:57

标签: git jenkins groovy

我正在使用Jenkins的Git plugin

我尝试访问$GIT_BRANCH环境变量并获得了null。然后,当我使用Groovy脚本打印环境变量时,我看到没有Git环境变量:

[PATH:/Library/Frameworks/Python.framework/Versions/3.5/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Users/octavian/.rvm/gems/ruby-2.2.1/bin:/Users/octavian/.rvm/gems/ruby-2.2.1@global/bin:/Users/octavian/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/spark/bin:/Library/TeX/texbin:/Users/octavian/.rvm/bin:/bin, IRBRC:/Users/octavian/.rvm/rubies/ruby-2.2.1/.irbrc, JAVA_ARCH:x86_64, _system_arch:x86_64, rvm_bin_path:/Users/octavian/.rvm/bin, TERM:xterm-256color, rvm_prefix:/Users/octavian, LANG:en_GB.UTF-8, COMMAND_MODE:unix2003, ITERM_SESSION_ID:w0t3p1:42062586-0BC3-48BB-B563-06F3F0CE98BF, LOGNAME:octavian, rvm_version:1.26.11 (latest), XPC_SERVICE_NAME:0, PWD:/Applications/Jenkins, TERM_PROGRAM_VERSION:3.0.8, SPARK_PATH:/usr/local/lib/spark-2.0.0-bin-hadoop2.7/bin, _:/usr/bin/java, SHELL:/bin/bash, TERM_PROGRAM:iTerm.app, _system_type:Darwin, MY_RUBY_HOME:/Users/octavian/.rvm/rubies/ruby-2.2.1, SECURITYSESSIONID:186a9, _system_version:10.11, OLDPWD:/Applications/Jenkins, USER:octavian, GEM_HOME:/Users/octavian/.rvm/gems/ruby-2.2.1, ITERM_PROFILE:Default, rvm_path:/Users/octavian/.rvm, TMPDIR:/var/folders/d8/dxrq0j_d10s7twghyd6v5tdr0000gn/T/, SSH_AUTH_SOCK:/private/tmp/com.apple.launchd.jnlVvcT4kt/Listeners, RUBY_VERSION:ruby-2.2.1, GEM_PATH:/Users/octavian/.rvm/gems/ruby-2.2.1:/Users/octavian/.rvm/gems/ruby-2.2.1@global, XPC_FLAGS:0x0, TERM_SESSION_ID:w0t3p1:42062586-0BC3-48BB-B563-06F3F0CE98BF, _system_name:OSX, __CF_USER_TEXT_ENCODING:0x1F5:0x0:0x0, Apple_PubSub_Socket_Render:/private/tmp/com.apple.launchd.1nXNOoW3kV/Render, com.apple.java.jvmTask:CommandLine, COLORFGBG:7;0, JAVA_MAIN_CLASS_75437:Main, HOME:/Users/octavian, SHLVL:1]

为了执行Jenkins脚本,我使用Groovy plugin,使用预步骤“执行系统Groovy脚本”和以下代码:

import hudson.model.*

def env = System.getenv()

println "env is: " + env

为什么我看不到任何GIT环境变量?

1 个答案:

答案 0 :(得分:0)

这将包含“ GIT_BRANCH

def branch = build.getEnvVars()["GIT_BRANCH"]
println "branch is: " + branch