Home > front end >  Jenkins workspace variable is swapping during parallel builds stages
Jenkins workspace variable is swapping during parallel builds stages

Time:01-31

I got a WS variable which is saving the Jenkins WORKSPACE variable. During stages I always check if the WS == WORKSPACE Jenkins generic variable. What I saw that during parallel runs ( when 2 different workspaces are created inside C:/jenkins/workspace@1 and C:/jenkins/workspace@2 the $WORKSPACE is swapping between those 2 parallels builds. enter image description here

The problem is reproduced rarely , less than 10 percent of cases but I find it quite strange , for the picture above -> The first workspace its AVB_Aplicattions_BOSCH-3 its going trough 3 stages and in the 4th stages the $WORKSPACE variable its swapping with AVB_APLICATTIONS_BOSCH-4( the other parallel build).If I will look on the other build (AVB_APLICATTIONS_BOSCH-4 I will see the same problem-> the workspace is becoming AVB_APLICATTIONS_BOSCH-3). During this builds I compile using cmake files, I'm afraid that the results will be not correct. I was thinking to use the in build dir() function during each stage to be sure im on the same workspace . Some one know a good approach for this case and also why its happening? I don't want to deactivate parallel's builds.

CodePudding user response:

The problem is that Jenkins variable scopes aren't really safe with parallel stages (see further sources / link). There are actually several questions and answers (and workaround) how to work with variables when using parallel stages. Long story short: don't use global variables but pay extra attention to define local variables with def to limit their scope:


Jenkins community links:

  • Related