首页 > 解决方案 > 如何将管道阶段变量传递给makefile

问题描述

我正在计算 jenkins 管道动态阶段内的局部变量 (S_STACK_ID) 的值我需要将 S_STACK_ID 变量传递给 makefile,以便它可以在 makefile 中用于唯一标识要部署的 ECS 堆栈

我试过下面的代码,但它通过空白'ARGS'到makefile

stage('build') {
            steps {
                script {
                    def stages = [failFast:true]
                    for (int i=1; i<5; i++) {
                            stages["LG ${i}"]={
                                stage ("LG ${i}"){
                                    S_STACK_ID=env.STACK_ID+i
                                    withCredentials([[
                                        sh 'make ARGS="${S_STACK_ID}" build'                                        
                                    }
                                }
                            }
                    }
                        parallel stages
                }
            }
        }

 sh 'make ARGS="myStack" build'  //This correclty passes "myStack" to makefile 

 sh 'make ARGS="${S_STACK_ID}" build' // Passess blank to makefile and not the value of S_STACK_ID which is an issue for me

谢谢

标签: bashmakefilejenkins-pipeline

解决方案


这是因为 shell 命令需要 "" 来插入字符串文字

sh "清理\"ARGS=${S_STACK_ID}\""


推荐阅读