首页 > 解决方案 > Jenkins Pipeline 在 Plaintex 中显示密码

问题描述

我正在从credentials插件中检索用户名密码。然后将这些值保存为环境变量。我在管道的后期阶段使用密码,在sh块中作为curl. 此时密码以明文形式显示在构建日志中。有没有办法避免这种情况?我假设通过使用credentials插件密码将被屏蔽。

pipeline {
 stages {
  stage ('One') {
  steps {
   withCredentials([userNamePassword(credentialsId: 'my_cred', userNameVariable: 'User_Name', passwordVariable: 'Password')]){
 env.User_Name = User_Name
 env.Password = Password
    }
  }
 }
 stage ('Two') {
   sh '''
    curl -v -u ${User_Name}:${Password} ...
    '''
  }
 }
}

注意:我正在使用将curl文件上传到远程主机。

标签: jenkinsgroovy

解决方案


我最终使用了块curl内部withCredentials

withCredentials([userNamePassword(credentialsId: 'my_cred', userNameVariable: 'User_Name', passwordVariable: 'Password')]){
   sh '''
    curl -v -u ${User_Name}:${Password} ...
      '''
}

推荐阅读