如何避免在多分支pipe道中进行双重结账

当运行一个工作时,SVN仓库被检出,将Jenkinsfile(存储在我的应用程序的根目录)放到workspace/branch_name@scriptworkspace/branch_name@script再次检出到workspace/branch_name

构build需要35-40分钟(大型应用程序,CakePHP)。

Jenkinsfile:

 #!groovy pipeline { agent any stages { stage('Build Environment & Test App') { steps { sh 'chmod +x ./scripts/* ./application/app/Console/cake' sh 'make test' junit 'junit.xml' } } } } 

做testing:

 #!/bin/bash -e CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # `JOB_BASE_NAME` set from Jenkins global environment variables export DOCKER_COMPOSE_PREFIX="${JOB_BASE_NAME:-test}" shopt -s expand_aliases alias docker-compose="docker-compose -p ${DOCKER_COMPOSE_PREFIX} -f ${CURRENT_DIR}/../docker/docker-compose.jenkins.yml" teardown() { echo -e "Destroying Docker containers and images" docker-compose down 1>/dev/null } # Bring up test environment trap teardown EXIT teardown echo -e "Bringing up Docker containers" docker-compose up -d php 1>/dev/null echo -e "Installing Composer" docker run --rm -v "${CURRENT_DIR}/../:/app" composer/composer install echo -e "Provisioning database" ./scripts/provision_db.sh 2>&1 >/dev/null docker-compose exec -T php /var/www/html/application/app/Console/cake test app AllNonIntegrationTests --stderr --log-junit /var/www/html/junit.xml || true 

控制台日志:

 Started by user admin Opening connection to svn://svn.example.com/repo/ Checking out svn svn://svn.example.com/repo/branches/branch_name into /var/jenkins_home/workspace/branch_name-76UIH4K7SPGC7K5MG4DAAVY3WRXZDDGD4CY3PVOOMQT2EGO3KLOA@script to read Jenkinsfile Checking out a fresh workspace because /var/jenkins_home/workspace/branch_name-76UIH4K7SPGC7K5MG4DAAVY3WRXZDDGD4CY3PVOOMQT2EGO3KLOA@script doesn't exist Cleaning local Directory . Checking out svn://svn.example.com/branches/branch_name at revision 15053 Using sole credentials admin/****** in realm '<svn://svn.example.com:3690> 12b84466-bdc2-49c8-9cd9-f855c9da5181' A Gruntfile.js <snipped rest of checkout> Running on master in /var/jenkins_home/workspace/branch_name-76UIH4K7SPGC7K5MG4DAAVY3WRXZDDGD4CY3PVOOMQT2EGO3KLOA [Pipeline] node [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Checkout SCM) [Pipeline] checkout Updating svn://svn.example/repo/branches/branch_name@15053 at revision 15053 Using sole credentials admin/****** in realm '<svn://svn.example.com:3690> 12b84466-bdc2-49c8-9cd9-f855c9da5181' <snipped rest of checkout> U . At revision 15053 No changes for svn://svn.example.com/repo/branches/branch_name since the previous build [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Build Environment & Test App) [Pipeline] sh <snipped output of 'make test'> [Pipeline] junit Recording test results [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS