I am trying to configure the pipeline to run automated e2e test on each PR to dev branch.
For that I am pulling the project, build it and when I want to run my tests I can not do this because when the project runs the pipeline doesn't switch to the second stage.
The question is when I build the project in Jenkins and it runs, how to force my test to run?
I tried parallel stage execution but it also doesn't work, because my tests start running when the project starts building.
My pipeline:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Cloning..'
git branch: 'dev', url: 'https://github.com/...'
echo 'Building..'
sh 'npm install'
sh 'npm run dev'
}
}
stage('e2e Test') {
steps {
echo 'Cloning..'
git branch: 'cypress-tests', url: 'https://github.com/...'
echo 'Testing..'
sh 'cd cypress-e2e'
sh 'npm install'
sh 'npm run dev'
}
}
}
}
CodePudding user response:
You can add a stage for cloning the test branch and then run the build and the test stages in the same tame using parallel
. The following pipeline should work:
pipeline {
agent any
stages {
stage ('Clone branchs') {
steps {
echo 'Cloning cypress-tests'
git branch: 'cypress-tests', url: 'https://github.com/...'
echo 'Cloning dev ..'
git branch: 'dev', url: 'https://github.com/...'
}
}
stage('Build and test') {
parallel {
stage('build') {
steps {
echo 'Building..'
sh 'npm install'
sh 'npm run dev'
}
}
stage('e2e Test') {
steps {
echo 'Testing..'
sh 'cd cypress-e2e'
sh 'npm install'
sh 'npm run dev'
}
}
}
}
}
Your will have the following pipeline:
CodePudding user response:
I can think of two potential ways to handle this:
Execute each stage on different node. So that different workspaces would be created for each stage.
Create separate directories for Build and E2E. cd into the relevant one for each stage and do the git checkout and the rest of the steps there.