Jenkins凭证-如何将凭证传递给“ cf login”命令?

时间:2019-03-21 18:39:35

标签: jenkins jenkins-pipeline cloudfoundry pivotal-cloud-foundry jenkins-groovy

当前,我们在Jenkins groovy(脚本化管道)中使用cf login命令,如下所示:

def login(url, uName, password, org, space){
    CONNECT = sh (
                    script: "cf login -a ${url} -u \"${uName}\" -p \"${password}\" -o ${org} -s ${space}",
                    returnStatus: true
                    ) == 0

}

但是现在Jenkins配置了以下凭据:

enter image description here 因此,我们不需要用户名/密码即可连接到Pivotal Cloud铸造厂


如何在脚本化管道中使用这些凭据?

1 个答案:

答案 0 :(得分:2)

def login(url, org, space){

    withCredentials([usernamePassword(credentialsId: 'AppsManager', usernameVariable: 'uName', passwordVariable: 'password')]) {
        CONNECT = sh (
                    script: "cf login -a ${url} -u \"${uName}\" -p \"${password}\" -o ${org} -s ${space}",
                    returnStatus: true
                ).trim()
    }

}