我正在嘗試配置管道以在每個 PR 到 dev 分支上運行自動化 e2e 測驗。
為此,我正在拉動專案,構建它,當我想運行我的測驗時,我不能這樣做,因為當專案運行時,管道不會切換到第二階段。
問題是當我在 Jenkins 中構建專案并運行時,如何強制我的測驗運行?
我嘗試了并行階段執行,但它也不起作用,因為我的測驗在專案開始構建時開始運行。
我的管道:
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'
}
}
}
}
uj5u.com熱心網友回復:
您可以添加一個用于克隆測驗分支的階段,然后使用parallel. 以下管道應該可以作業:
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'
}
}
}
}
}
您將擁有以下管道:

uj5u.com熱心網友回復:
我可以想到兩種可能的方法來處理這個問題:
在不同的節點上執行每個階段。以便為每個階段創建不同的作業空間。
為 Build 和 E2E 創建單獨的目錄。cd 到每個階段的相關一個,然后執行 git checkout 和那里的其余步驟。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/370427.html
