使用凭据插件运行Jenkins管道步骤的问题

时间:2019-01-14 10:53:40

标签: jenkins jenkins-plugins jenkins-pipeline

我有一个基本的管道,可将目录复制到远程目录。如果我的用户名和密码为纯文本格式,则可以正常工作,但是当我尝试使用withCredentials时,会出现身份验证错误。有某种语法可以引用吗?管道如下

<div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
  <div
    class="example-box"
    *ngFor="let item of items"
    cdkDrag
    [cdkDragDisabled]="item.disabled">{{item.value}}</div>
</div>

我在下面收到错误消息

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'
    }
}

1 个答案:

答案 0 :(得分:0)

执行此操作的方法是调用不带引号或$的变量,如下所示

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