使用错误的工作目录的Ssh-agent步骤

时间:2018-03-08 09:15:21

标签: jenkins jenkins-pipeline

突然,没有任何管道更改,ssh-agent插件使用了错误的workingdir。我在部署步骤中使用它将rsync文件同步到测试服务器环境。

[project@2] Running shell script <-- build step
[project@2] Running shell script <-- test step
[project] Running shell script <-- deployment step

正如您在上面所看到的那样,错误的工作目录(没有@ 2)用于部署而没有前面步骤的构建。

pipeline {
  agent any
  stages {
    stage('Build') {
      agent {
        docker {
          image 'composer:latest'
        }
      }
      steps {
        sh 'composer install --ignore-platform-reqs'
      }
    }
    stage('Test') {
      agent {
        docker {
          image 'php:7.1.13-cli'
        }        
      }
      steps {
        sh './vendor/bin/phpunit'
      }
    }
    stage('Deploy') {
      steps {
        sshagent (credentials: ['PROJECT_KEY']) {
          sh 'rsync \
                -a \
                --delete \
                --exclude="*local.php" \
                --exclude=".*" \
                --include="config/***" \
                --include="module/***" \
                --include="vendor/***" \
                --include="shell/***" \
                --include="bin/***" \
                --include="init_autoloader.php" \
                --exclude="*" \
                -e "ssh -p 2222" \
                . username@*****.com:/data/sites/test.*****.com/'
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

您似乎忘了为最后一个阶段确定agent。您可以在agent上运行管道。在这种情况下,在开头标识`agent。

相关问题