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"
                     }
                    }
                }
            }
            
        }
    }
  • 相关阅读:
    利用MFC获取网页内容
    IP地址 >实际地址 ,API 查询
    一个小时内学习 SQLite 数据库
    Sqlite c/c++ api 学习
    笔记
    Sqlite的操作(增加,删除,查询,修改)
    免费天气API
    ServerSocketChannel的使用例子
    各种模式一览
    什么事文件描述符
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/13524138.html
Copyright © 2011-2022 走看看