linux - Jenkinsfile 环境变量未反射(reflect)在脚本部分中调用的 Makefile 中

标签 linux jenkins makefile jenkins-pipeline

我有下面的 jenkins 文件,我试图在 make 文件中打印在 jenkins 文件中定义的环境变量。但是,它不会反射(reflect)在 make 文件中。它仍然是空的。

pipeline {
  environment {
      CREDS = credentials('some jenkins credential id')
  }
  agent{
     kubernetes {
        label 'mypod'
        containerTemplate {
            name 'ubuntu'
            image 'ubuntu:16.04'
            ttyEnabled true
            command 'cat'
        }
    }
  }
  stages{
      stage('execute Makefile'){
         script{
           sh"""
             make print-jenkinsfile-env-var

             echo ${CREDS_USR}
             echo ${CREDS}

            """
         }

      }
  }
}

下面是我的 Makefile:

usercred := $(CREDS)
export usercred
username := $(CRED_USR)
export username
testuser := 'newvar'
export testuser
print-jenkinsfile-env-var:
     @echo "$$usercred"
     @echo "$$username"
     @echo "$$testuser"

建议在 make 文件中进行编辑,它也没有打印。

usercred := $(CREDS)
export usercred
username := $(CRED_USR)
export username
testuser := 'newvar'
export testuser
print-jenkinsfile-env-var:
     @echo $(usercred)
     @echo $(username)
     @echo "$$testuser"

Testuser 被打印出来,因为它是在 Makefile 中定义的,但其他两个变量打印为空。 我可以在脚本部分显式打印环境变量,但不能通过 makefile。

我正在寻找下面的工作

push-package:
#tgz file creation step
#push the package 
@curl -u $(CREDS) -X PUT "jfrog artifactory repo url" -T *tgz

但是,我的 Makefile 没有获得 Jenkins 文件环境中存在的 $(CRED) 的值。但是,我可以在 Jenkinsfile 中执行如下相同的脚本

curl -u ${CREDS} -X PUT "jfrog artifactory repo url" -T *tgz

有人可以推荐吗?

最佳答案

在对我的帖子发表评论的 Zelnes 的帮助下,我进行了以下更改,并且能够将 jenkinsfile env var 用于我的 makefile。我在 jenkins 文件中做了以下更改。

script{
       sh"""
         make print-jenkinsfile-env-var CREDS=${CREDS}

        """
     }

关于linux - Jenkinsfile 环境变量未反射(reflect)在脚本部分中调用的 Makefile 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51395820/

相关文章:

linux - bash 脚本中出现 "Unexpected end of file"错误

linux - 颠覆预提交 Hook 错误代码 255

包含版本号的 Git 日志

android - Jenkins : ionic 安卓构建失败

C++ 包含和 Makefile

c - UEFI hello world编译错误

c - 如何延迟分配归零内存?

尝试 new 移动到新的 python 版本后出现 Python "command not found"

python - 是否可以在不使用 jenkins 上的 "PyAutoGUI"库的情况下使用键盘操作?

c++ - 如何使用 GoogleTest 避免混合测试和生产代码?