【问题标题】:Issue running Jenkins Pipeline Steps using Credentials plugin使用凭据插件运行 Jenkins 流水线步骤的问题
【发布时间】:2019-01-14 19:24:15
【问题描述】:

我有一个将目录复制到远程目录的基本管道。如果我有纯文本的用户名和密码,它可以正常工作,但是当我尝试使用 withCredentials 时,我会遇到身份验证错误。是否有特定的语法来引用它?流水线如下

node {
    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'creds-id', usernameVariable: 'username', passwordVariable: 'password']]){

    def remote = [:]
    remote.name = 'EU Server 1'
    remote.host = 'server1@server.com'
    remote.user = '$username'
    remote.password = '$password'
    remote.allowAnyHosts = true

    stage('Copy dir to server'){
        sshPut remote: remote, from: '/data/workspace', into: '/home/server1/workspace1'
    }
}

我收到以下错误

com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:519)
at com.jcraft.jsch.Session.connect(Session.java:183)
at com.jcraft.jsch.Session$connect$6.call(Unknown Source)

【问题讨论】:

    标签: jenkins jenkins-plugins jenkins-pipeline


    【解决方案1】:

    这样做的方法是调用不带引号或$的变量,如下所示

    def remote = [:]
    remote.name = 'EU Server 1'
    remote.host = 'server1@server.com'
    remote.user = username
    remote.password = password
    remote.allowAnyHosts = true
    
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多