- 创建全局凭据
- 在pipeline中引用这个 账号密码
- 唯一需要改动的就是 credentialsId 这个值就是你创建凭据时生成的ID , 你可以自己写 , 如果是空的 那么jenkins将会帮你生成
steps { withCredentials([usernamePassword(credentialsId: 'f1ae8e1e-b082-49de-89fb-a99e514b62bb', passwordVariable: 'password', usernameVariable: 'username')]) { sh '''docker login -u $username -p $password registry.cn-hangzhou.aliyuncs.com docker tag jenkins-demo registry.cn-hangzhou.aliyuncs.com/conlon/jenkins-demo-repository:latest docker push registry.cn-hangzhou.aliyuncs.com/conlon/jenkins-demo-repository:latest''' } }