jenkinsgroovyjenkins-scriptler

Are 2 jobs running in pipeline of jenkins thread safe?


I am running two jobs in jenkins in two pipeline. These two projects use build parameter from a previous build. These build parameters are created as follows:

 def buildVariables = lastSuccBuild.getBuildVariables()
 nextPluginVersion = buildVariables.get("PluginNextVersion")

    List<StringParameterValue> parameterValuesAl = new ArrayList<StringParameterValue>();
    parameterValuesAl.add(new StringParameterValue("PluginNextVersion", nextPluginVersion.toString()))
    parameterValuesAl.add(new StringParameterValue("PluginMajorVersion", majorVersion.toString()))
    parameterValuesAl.add(new StringParameterValue("PluginBuildVersion", buildVersion.toString()))


    def versions = new ParametersAction(parameterValuesAl)

    // add variable to current job
    Thread.currentThread().executable.addAction(versions)

    } catch (Throwable t) {
      println(t)
      t.printStackTrace()
      throw t;
    }

Both the jobs uses same script with same variables.

Can this cause a problem if two builds execute simultaneously?


Solution

  • No this will not cause any problem.

    As two pipelines are different, all resources shared by pipeline are different. So if same script is being used by two builds in two pipelines, then variables will have different context.