如何避免多分支管道中的双重结账

时间:2017-09-06 18:03:26

标签: cakephp docker svn jenkins multibranch-pipeline

当运行作业时,SVN仓库会被检出以将Jenkins文件(存储在我的应用程序的根目录中)存入workspace/branch_name@script,并且repo会再次结帐到workspace/branch_name

构建需要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'
            }
        }
    }
}

进行测试:

#!/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

0 个答案:

没有答案