jenkins 调用其他系统信息加密
如 脚本使用 docker login -u root -p passwd 的时候会明文显示在脚本,我们可以在 Jenkins 中定义使用环境变量并使用,但是这样使用会在 jenkins 的构建过程中明文显示,此时使用插件。以下以 harbor 信息为例,cos 等同理使用。
Jenkins 安装插件
Jenkins 定义变量
创建 harbor domin 来存储 harbor 相关信息 |
 |
增加 harbor_docker_host |
增加 harbor_docker_name |
增加 harbor_docker_passwd |
 |
 |
 |
harbor 信息填写完成,Jenkinsfile 中使用 harbor_docker_passwd=credentials('harbor_docker_passwd') 方式定义为加密变量 |
 |
Jenkins 使用变量
pipeline {
environment {
harbor_docker_host=credentials('harbor_docker_host')
harbor_docker_name=credentials('harbor_docker_name')
harbor_docker_passwd=credentials('harbor_docker_passwd')
}
agent any
stages {
stage('Docker Build') {
steps {
// 构建 Docker 镜像
sh 'docker build -t datarc:latest .'
sh 'docker login -u ${harbor_docker_name} -p "${harbor_docker_passwd}" ${harbor_docker_host}'
sh 'docker tag datarc:latest ${harbor_docker_host}/datarc-web/datarc-web:v1'
sh 'docker push ${harbor_docker_host}/datarc-web/datarc-web:v1'
}
}
}
post {
always {
cleanWs deleteDirs: true, patterns: [[pattern: '*', type: 'INCLUDE']]
}
}
}
查看效果
查看构建过程发现 相关信息都已经加密 |
 |