Jenkins $in凭证绑定+;声明性管道的疯狂逃离

Jenkins $in凭证绑定+;声明性管道的疯狂逃离,jenkins,jenkins-plugins,jenkins-pipeline,Jenkins,Jenkins Plugins,Jenkins Pipeline,这是我的密码:“ASD123$567” 这不管用 withCredentials([usernamePassword(credentialsId: 'creds', usernameVariable: 'myuser', passwordVariable: 'mypass')]) { sh "some command --username ${myuser} --password ${mypass}" } 我在输出中看到的是mypass没有被混淆,最重要的是它看起来像是在“$”

这是我的密码:“ASD123$567”

这不管用

withCredentials([usernamePassword(credentialsId: 'creds',
    usernameVariable: 'myuser', passwordVariable: 'mypass')]) {
    sh "some command --username ${myuser} --password ${mypass}"
}
我在输出中看到的是mypass没有被混淆,最重要的是它看起来像是在“$”之后被切断了,所以它只显示为ASD123

编辑:我有点搞不清楚这是哪里出了问题,看起来它实际上是转换到Shell步骤的,这就是问题的具体原因。

我的解决方案(如果你想这样称呼它):


您可以使用凭据功能:

pipeline {
  ...
  stage("Credentials") {
    environment {
      MY_CREDENTIAL = credentials('creds')
    }
    steps {
      // Single quotes!
      sh 'echo ${MY_CREDENTIAL}'
      sh 'echo ${MY_CREDENTIAL_USR}:${MY_CREDENTIAL_PSW}'
    }
  }
}

有关更多信息,请查看

我在没有
sshagent的情况下执行一些远程ssh脚本时遇到了同样的问题。我的密码中有几个$,需要作为参数输入到
mysql-p

被接受的解决方案对我不起作用,因为当我通过它们时,没有一块钱逃走。 我最终使用两种建议解决方案的组合解决了这个问题
${mypass.replaceAll('\\$,'\\$)}


这是一个怎样的解决方案?这是一个已知的问题,$$works?你能试试-密码“\$mypass\”?这似乎失败了管道哇,他们需要更新他们的文档,我不认为它支持用户名密码绑定完全有效,而且似乎我可以注入groovy变量,只要我将其包装在
echo'${myVarWithdollar}中
让bash知道它是一个文本字符串
pipeline {
  ...
  stage("Credentials") {
    environment {
      MY_CREDENTIAL = credentials('creds')
    }
    steps {
      // Single quotes!
      sh 'echo ${MY_CREDENTIAL}'
      sh 'echo ${MY_CREDENTIAL_USR}:${MY_CREDENTIAL_PSW}'
    }
  }
}
pipeline {
  ...
  stage("Credentials") {
    environment {
      MY_CREDENTIAL = credentials('creds')
    }
    steps {
      // Single quotes!
      sh """ 
          ssh user@server "
               mysqldump -u${MY_CREDENTIAL_USR} -p'${MY_CREDENTIAL_PSW.replaceAll('\$','\\\$')}' DBNAME > dump.sql
          "
         """
    }
  }
}