У меня был следующий скрипт, правильно работающий на одном Jenkins:
def serenityBatches = [:]
pipeline {
agent any
parameters {
string(defaultValue: '6', description: 'Number of test batches that should runindividually, either parallel or batch after batch', name: 'batchCount')
string(defaultValue: '1', description: 'Number of tests/browsers that can run simultaniously on one node', name: 'forkCount')
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
disableConcurrentBuilds()
}
stages {
stage('Clean workspace') {
steps {
withMaven(){ sh "mvn clean" }
}
}
stage('Create batches') {
steps {
script {
def batchCount = params.batchCount.toInteger()
def forkCount = params.forkCount.toInteger()
setJobDescription( batchCount, forkCount )
for (int i = 1; i <= batchCount; i++) {
def batchNumber = i
def batchName = "batch${batchNumber}"
serenityBatches[batchName] = {
node {
stage("batch${batchNumber} checkout") {
cleanWs()
checkoutFromSvn()
}
stage("batch${batchNumber} testing") {
runTests(batchNumber, batchCount, forkCount)
}
}
}
}
}
}
}
stage('Execute tests') {
steps {
script {
parallel serenityBatches
}
}
}
stage('Generate Report') {
steps {
collectReportsFromAllBatches()
aggregateReports()
publishReport()
zulipNotification stream: 'xxy', topic: 'AutoTests'
}
}
}
post {
changed {
script {
// report back to normal after failure
if(hudson.model.Result.FAILURE.equals(currentBuild.getPreviousBuild().result)) {
zulipNotification stream: 'xxy', topic: 'AutoTests'
}
}
}
}
}
void checkoutFromSvn() {
checkout changelog: false,
scm: [ $class: 'SubversionSCM',
locations: [[ cancelProcessOnExternalsFail: true,
credentialsId: 'someID',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: '.',
remote: 'https://whatever',
clearWorkspace: true
]],
quietOperation: true,
workspaceUpdater: [$class: 'UpdateUpdater']
]
}
void runTests(batchNumber, batchCount, forkCount) {
try {
withMaven(){
sh "mvn clean"
sh "rm -rf target/site/serenity"
sh "mvn -U verify -Dparallel.tests=${forkCount} -Dserenity.batch.count=${batchCount} -Dserenity.batch.number=${batchNumber}"
}
} catch (Throwable e) {
throw e
} finally {
stash name: getStashId(batchNumber), excludes: "**", allowEmpty: true
stash name: getStashId(batchNumber), includes: "target/site/serenity/**/*", allowEmpty: true
}
}
String getStashId(int batchNumber) {
return "$JOB_NAME".replace('/','_')+"-$BUILD_NUMBER-batch-${batchNumber}"
}
/** unstash each of the batches **/
void collectReportsFromAllBatches() {
script {
def batchCount = params.batchCount.toInteger()
for (int batchNumber = 1; batchNumber <= batchCount; batchNumber++) {
def stashName = getStashId(batchNumber)
unstash stashName
}
}
}
void aggregateReports() {
withMaven(){ sh "mvn serenity:aggregate" }
}
/** publish the Serenity report **/
void publishReport() {
publishHTML(target: [
reportName : 'Serenity Report',
reportDir: 'target/site/serenity',
reportFiles: 'index.html',
keepAll: true,
alwaysLinkToLastBuild: true,
allowMissing: false
])
}
void setJobDescription(int batchCount, int forkCount) {
currentBuild.description = "batches:$batchCount forks:$forkCount"
}
Но теперь мы переходим к другому Jenkins, где есть определенные c узлы для тестирования (хром), поэтому я пытаюсь адаптировать скрипт для запуска там. Я могу запустить оригинальный скрипт там, но, очевидно, тесты будут выполняться на случайных узлах, поэтому они не пройдут. Следующий скрипт дает мне «Не найден такой агент DSL-метода» среди шагов », я не совсем понимаю. Уже пробовал много разных комбинаций ... пока безуспешно.
def serenityBatches = [:]
pipeline {
agent any
parameters {
string(defaultValue: '6', description: 'Number of test batches that should runindividually, either parallel or batch after batch', name: 'batchCount')
string(defaultValue: '1', description: 'Number of tests/browsers that can run simultaniously on one node', name: 'forkCount')
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
disableConcurrentBuilds()
}
stages {
stage('Clean workspace') {
steps {
withMaven(maven: 'Maven 3.6.1'){ sh "mvn clean" }
}
}
stage('Create batches') {
steps {
script {
def batchCount = params.batchCount.toInteger()
def forkCount = params.forkCount.toInteger()
setJobDescription( batchCount, forkCount )
for (int i = 1; i <= batchCount; i++) {
def batchNumber = i
def batchName = "batch${batchNumber}"
serenityBatches[batchName] = {
stage("batch${batchNumber} checkout") {
agent { label 'chrome' }
steps {
cleanWs()
checkoutFromSvn()
runTests(batchNumber, batchCount, forkCount)
}
}
}
}
parallel serenityBatches
}
}
}
stage('Generate Report') {
steps {
collectReportsFromAllBatches()
aggregateReports()
publishReport()
zulipNotification stream: 'xxy', topic: 'AutoTests'
}
}
}
post {
failure {
zulipNotification stream: 'xxy', topic: 'AutoTests'
}
changed {
script {
// report back to normal after failure
if(hudson.model.Result.FAILURE.equals(currentBuild.getPreviousBuild().result)) {
zulipNotification stream: 'xxy', topic: 'AutoTests'
}
}
}
}
}
void checkoutFromSvn() {
checkout changelog: false,
scm: [ $class: 'SubversionSCM',
locations: [[ cancelProcessOnExternalsFail: true,
credentialsId: 'someID',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: '.',
remote: 'https://whatever',
clearWorkspace: true
]],
quietOperation: true,
workspaceUpdater: [$class: 'UpdateUpdater']
]
}
void runTests(batchNumber, batchCount, forkCount) {
try {
withMaven(maven: 'Maven 3.6.1'){
sh "mvn clean"
sh "rm -rf target/site/serenity"
sh "mvn -U verify -Dparallel.tests=${forkCount} -Dtest=LoggedInUserStaysLoggedInTDTest -Dserenity.batch.count=${batchCount} -Dserenity.batch.number=${batchNumber} -Dheadless.mode=true"
}
} catch (Throwable e) {
throw e
} finally {
stash name: getStashId(batchNumber), excludes: "**", allowEmpty: true
stash name: getStashId(batchNumber), includes: "target/site/serenity/**/*", allowEmpty: true
}
}
String getStashId(int batchNumber) {
return "$JOB_NAME".replace('/','_')+"-$BUILD_NUMBER-batch-${batchNumber}"
}
/** unstash each of the batches **/
void collectReportsFromAllBatches() {
script {
def batchCount = params.batchCount.toInteger()
for (int batchNumber = 1; batchNumber <= batchCount; batchNumber++) {
def stashName = getStashId(batchNumber)
unstash stashName
}
}
}
void aggregateReports() {
withMaven(maven: 'Maven 3.6.1'){ sh "mvn serenity:aggregate" }
}
/** publish the Serenity report **/
void publishReport() {
publishHTML(target: [
reportName : 'Serenity Report',
reportDir: 'target/site/serenity',
reportFiles: 'index.html',
keepAll: true,
alwaysLinkToLastBuild: true,
allowMissing: false
])
}
void setJobDescription(int batchCount, int forkCount) {
currentBuild.description = "batches:$batchCount forks:$forkCount"
}