image.png

简单pipeline脚本

  1. pipeline {
  2. agent any
  3. stages {
  4. stage('拉取代码') {
  5. steps {
  6. echo '拉取代码'
  7. }
  8. }
  9. stage('编译构建') {
  10. steps {
  11. echo '编译构建'
  12. }
  13. }
  14. stage('项目部署') {
  15. steps {
  16. echo '项目部署'
  17. }
  18. }
  19. }
  20. }

image.png
点击构建
可以看到每个步骤花费的时间
image.png
可以看到每个步骤日志
image.png

pipeline-ssh远程主机执行脚本

def getRemoteServer(ip){
      def remote = [:]
      remote.name = 'root'
      remote.host = ip
      remote.user = 'root'
      remote.password = 'xxxxxxxxxxx'
      remote.allowAnyHosts = true

    // withCredentials([usernamePassword(credentialsId: 'wukang', passwordVariable: 'password', usernameVariable: 'userName')]) {
    //     remote.user = "${userName}"
    //     remote.password = "${password}"
    // }
    return remote

}

pipeline {
    agent any
    stages {
        stage('连接跳板机') {
            steps {
                script{
                    remote = getRemoteServer("192.168.0.9")
                    sshCommand remote: remote, command: "ls -lrt"
                    sshCommand remote: remote, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"
                }
            }
        }
        stage('拉取代码') {
            steps {
                echo '拉取代码'
            }
        }
        stage('编译构建') {
            steps {
                echo '编译构建'
            }
        }
        stage('项目部署') {
            steps {
                echo '项目部署'
                // sh 'ansible all -m ping'
            }
        }
    }
}