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

问题描述 投票:-3回答:1

目前我们在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代工厂


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

jenkins jenkins-pipeline cloudfoundry pivotal-cloud-foundry jenkins-groovy
1个回答
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()
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.