Jenkins Pipeline 密钥实现远程部署

发布时间 2023-06-12 17:27:37作者: 小油2018

前提:

已配置jenkins秘钥凭证

 

一、配置流程

1.1 片段生成

1、按如下图选择

image-20220719122921121

2、新增密钥信息

image-20220719133057946

1.2 脚本配置

以上配置完成后,接下来就可以在 Jenkinsfile 中配置了,:

 stages {
    stage('xx启动') {

       steps {
            echo "xx启动"
            dir("${SRC_PATH}") {
            withCredentials([sshUserPrivateKey(credentialsId: 'IDC-xx-xx', keyFileVariable: 'identity', usernameVariable: 'USERNAME')]) {
                    sh 'ssh -o StrictHostKeyChecking=no -p 10022 -i ${identity} ${USERNAME}@122.xx.xx.xx "cd /home/; mkdir -p hello"'
                }        
        }
        }
    }
  } 

 

参考:

https://blog.csdn.net/IT_ZRS/article/details/125870679