将sh输出分配给声明管道上的变量

时间:2018-06-25 13:23:04

标签: jenkins jenkins-pipeline

如何使用声明性管道将sh输出分配给变量?

def arch_prefix() { 
    script {  
        return sh(script : 'uname -m', returnStdout: true).trim()
    }
}
// end - Auxiliary fuctions

pipeline {
    agent none

    environment {
        DOCKER_IMAGE = 'test'
        ARCHITECTURE = arch_prefix()
        DOCKER_IMG = "${DOCKER_IMAGE}-${ARCHITECTURE}"
    }
    stages {
        stage('Build') {
            parallel {
                stage('arch1') {
                    agent { label 'agent_a' }
                    steps {
                        echo "${DOCKER_IMG}"
                    }
            stage('arch2') {
                    agent { label 'agentb' }
                    steps {
                        echo "${DOCKER_IMG}"
                    }
                }
            }
        }
    }
}

0 个答案:

没有答案