@@ -24,11 +24,12 @@ pipeline {
2424 quietPeriod(10 )
2525 }
2626 triggers {
27- issueCommentTrigger(' (?i).*(?:jenkins\\ W+)?run\\ W+(?:the\\ W+)?tests(?:\\ W+please)?.*' )
27+ issueCommentTrigger(' (?i).*(?:jenkins\\ W+)?run\\ W+(?:the\\ W+)?(?:module \\ W+)? tests(?:\\ W+please)?.*' )
2828 }
2929 parameters {
3030 booleanParam(name : ' Run_As_Master_Branch' , defaultValue : false , description : ' Allow to run any steps on a PR, some steps normally only run on master branch.' )
3131 booleanParam(name : ' tav_ci' , defaultValue : true , description : ' Enable TAV tests.' )
32+ booleanParam(name : ' tests_ci' , defaultValue : true , description : ' Enable tests.' )
3233 booleanParam(name : ' test_edge_ci' , defaultValue : true , description : ' Enable tests for edge versions of nodejs.' )
3334 }
3435 stages {
@@ -42,6 +43,15 @@ pipeline {
4243 deleteDir()
4344 gitCheckout(basedir : " ${ BASE_DIR} " , githubNotifyFirstTimeContributor : true )
4445 stash allowEmpty : true , name : ' source' , useDefaultExcludes : false
46+ script {
47+ dir(" ${ BASE_DIR} " ){
48+ def regexps = [
49+ " ^lib/instrumentation/modules/" ,
50+ " ^test/instrumentation/modules/"
51+ ]
52+ env. TAV_UPDATED = isGitRegionMatch(regexps : regexps)
53+ }
54+ }
4555 }
4656 }
4757 /**
@@ -74,6 +84,10 @@ pipeline {
7484 environment {
7585 HOME = " ${ env.WORKSPACE} "
7686 }
87+ when {
88+ beforeAgent true
89+ expression { return params. tests_ci }
90+ }
7791 steps {
7892 withGithubNotify(context : ' Test' , tab : ' tests' ) {
7993 deleteDir()
@@ -87,10 +101,17 @@ pipeline {
87101 script {
88102 def node = readYaml(file : ' .ci/.jenkins_nodejs.yml' )
89103 def parallelTasks = [:]
104+ def parallelTasksWithoutAsyncHooks = [:]
90105 node[' NODEJS_VERSION' ]. each{ version ->
91106 parallelTasks[" Node.js-${ version} " ] = generateStep(version : version)
107+ parallelTasksWithoutAsyncHooks[" Node.js-${ version} -async-hooks-false" ] = generateStep(version : version)
92108 }
109+
110+ env. ELASTIC_APM_ASYNC_HOOKS = " true"
93111 parallel(parallelTasks)
112+
113+ env. ELASTIC_APM_ASYNC_HOOKS = " false"
114+ parallel(parallelTasksWithoutAsyncHooks)
94115 }
95116 }
96117 }
@@ -115,21 +136,21 @@ pipeline {
115136 expression { return params.Run_As_Master_Branch }
116137 triggeredBy ' TimerTrigger'
117138 changeRequest()
139+ expression { return env. TAV_UPDATED != " false" }
118140 }
119141 expression { return params. tav_ci }
120142 }
121143 }
122144 steps {
123- withGithubNotify(context : ' TAV Test' , tab : ' tests' ) {
124- deleteDir()
125- unstash ' source'
126- dir(" ${ BASE_DIR} " ){
127- script {
128- def node = readYaml(file : ' .ci/.jenkins_tav_nodejs.yml' )
129- def tav = readYaml(file : ' .ci/.jenkins_tav.yml' )
145+ deleteDir()
146+ unstash ' source'
147+ dir(" ${ BASE_DIR} " ){
148+ script {
149+ def tavContext = getSmartTAVContext()
150+ withGithubNotify(context : tavContext. ghContextName, description : tavContext. ghDescription, tab : ' tests' ) {
130151 def parallelTasks = [:]
131- node[' NODEJS_VERSION' ]. each{ version ->
132- tav[' TAV' ]. each{ tav_item ->
152+ tavContext . node[' NODEJS_VERSION' ]. each{ version ->
153+ tavContext . tav[' TAV' ]. each{ tav_item ->
133154 parallelTasks[" Node.js-${ version} -${ tav_item} " ] = generateStep(version : version, tav : tav_item)
134155 }
135156 }
@@ -271,7 +292,13 @@ def generateStep(Map params = [:]){
271292 dir(" ${ BASE_DIR} " ){
272293 retry(2 ){
273294 sleep randomNumber(min :10 , max : 30 )
274- sh(label : " Run Tests" , script : """ .ci/scripts/test.sh "${ version} " "${ tav} " "${ edge} " """ )
295+ if (version?. startsWith(' 6' )) {
296+ catchError {
297+ sh(label : ' Run Tests' , script : """ .ci/scripts/test.sh "${ version} " "${ tav} " "${ edge} " """ )
298+ }
299+ } else {
300+ sh(label : " Run Tests" , script : """ .ci/scripts/test.sh "${ version} " "${ tav} " "${ edge} " """ )
301+ }
275302 }
276303 }
277304 } catch (e){
@@ -286,3 +313,44 @@ def generateStep(Map params = [:]){
286313 }
287314 }
288315}
316+
317+ /**
318+ * Gather the TAV context for the current execution. Then the TAV stage will execute
319+ * the TAV using a smarter approach.
320+ */
321+ def getSmartTAVContext () {
322+ context = [:]
323+ context. ghContextName = ' TAV Test'
324+ context. ghDescription = context. ghContextName
325+ context. node = readYaml(file : ' .ci/.jenkins_tav_nodejs.yml' )
326+
327+ if (env. GITHUB_COMMENT ) {
328+ def modules = getModulesFromCommentTrigger(regex : ' (?i).*(?:jenkins\\ W+)?run\\ W+(?:the\\ W+)?module\\ W+tests\\ W+for\\ W+(.+)' )
329+ if (modules. isEmpty()) {
330+ context. ghDescription = ' TAV Test disabled'
331+ context. tav = readYaml(text : ' TAV:' )
332+ context. node = readYaml(text : ' NODEJS_VERSION:' )
333+ } else {
334+ if (modules. find{ it == ' ALL' }) {
335+ context. tav = readYaml(file : ' .ci/.jenkins_tav.yml' )
336+ } else {
337+ context. ghContextName = ' TAV Test Subset'
338+ context. ghDescription = ' TAV Test comment-triggered'
339+ context. tav = readYaml(text : """ TAV:${ modules.collect{ "\n - ${it}"}.join("") } """ )
340+ }
341+ }
342+ } else if (params.Run_As_Master_Branch ) {
343+ context. ghDescription = ' TAV Test param-triggered'
344+ context. tav = readYaml(file : ' .ci/.jenkins_tav.yml' )
345+ } else if (changeRequest() && env. TAV_UPDATED != " false" ) {
346+ context. ghContextName = ' TAV Test Subset'
347+ context. ghDescription = ' TAV Test changes-triggered'
348+ sh ' .ci/scripts/get_tav.sh .ci/.jenkins_generated_tav.yml'
349+ context. tav = readYaml(file : ' .ci/.jenkins_generated_tav.yml' )
350+ } else {
351+ context. ghDescription = ' TAV Test disabled'
352+ context. tav = readYaml(text : ' TAV:' )
353+ context. node = readYaml(text : ' NODEJS_VERSION:' )
354+ }
355+ return context
356+ }
0 commit comments