zoukankan      html  css  js  c++  java
  • Jenkins执行 remote SSH 命令

    1.安装 SSH Pipeline Steps 插件

    2.在凭据中添加remote server凭据,如下

    3.Pipeline编写:

    def GetRemoteServer(ip){
        def remote = [:]
        remote.name = ip
        remote.host = ip
        remote.port = 22
        remote.allowAnyHosts = true
        //通过withCredentials调用Jenkins凭据中已保存的凭据,credentialsId需要填写,其他保持默认即可
        withCredentials([usernamePassword(credentialsId: 'c0c1281-36df-4c5-b26d-dcf5208776f', passwordVariable: 'password', usernameVariable: 'userName')]) {
            remote.user = "${userName}"
            remote.password = "${password}"
        }
        return remote
    }
    
    
    pipeline{
        agent any
        stages{
    
            stage("任务申请"){
                steps{
                     script{
                      //调用上面定义好的方法
                      rserver = GetRemoteServer('10.10.2.11')
                      sshCommand remote: rserver, command: "ifconfig" //在remote server上执行ifconfig命令
    
                     }
                    }
                }
            }
    
        }
    }

    方法二,不定义方法,直接使用:

    def remote = [:]
    remote.name = 'saltm'
    remote.host = '10.10.2.11'
    remote.user = 'root'
    remote.password = '1qjRg'
    remote.allowAnyHosts = true
    
    pipeline{
        agent any
        stages{
    
            stage("任务申请"){
                steps{
                     script{
                         
                      sshCommand remote: remote, command: "ifconfig |grep inet"
                     }
                    }
                }
            }
            
        }
    }
  • 相关阅读:
    @topcoder
    @uoj
    Vue-路由跳转的几种方式和路由重定向
    Vue-设置默认路由选中
    Vue-使用webpack+vue-cli搭建项目
    Vue-状态管理Vuex的使用
    Vue-全局变量和方法
    JS-apply、call、bind
    CSS-禁止文本被选中
    Vue-路由模式 hash 和 history
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/13524138.html
Copyright © 2011-2022 走看看