Passing the result from the Parameterized Trigger plugin

I have 2 tasks: "Helper" and "Primary" and the only jenkins instance (which is the host and the executor).

The assistant manages a third-party resource and prepares the main task (more precisely, it creates an environment for deploying an application for testing).

The only artifact for the auxiliary task is a single file with the IP address of the environment, prepared specifically for the main task.

How would I move the assembly from Helper to Main in this case?

+4
source share
2 answers

You say that you need to transfer the file with the IP address to the "Basic" task. If all you need is an IP, there are simpler ways to do this (without files), I will describe both.

To transfer an artifact from one job to another

In the Assistant task, you need to archive this file from the workspace.

  • In post-assembly actions, select Archive Artifacts
  • Position the path relative to the work area. You can use wildcards or a hardcode file name if it is always the same.
  • Configure this task to automatically launch your main task using the Trigger / Calls command on other projects . If you do not have this plugin, you can get it here
  • For build projects, enter the name of your main job

Now, in the "Basic" task, you need to copy this artifact from the previous task ("Helper").

  • For the first build step, select Copy artifacts from another project . If you do not have this plugin, you can get it here
  • For Project Name, enter the name of your Assistant job.
  • For Which build, select Last Successful Build
  • For Artifacts to copy, use **/yourartifactname*.* . The name of your artifact will be what you configured in the Assistant task. Using **/ in front ensures that it will ignore any directory structure before moving on to the artifact
  • For the Target directory, specify the location in the workspace "Primary" workspace where this file will also be copied.
  • Checkmark Flatten directories , so the file goes directly to the location specified in step 5, otherwise it will save the directory structure to which it was archived (in the Assistant task)

Now your โ€œmainโ€ task has a file from the โ€œHelperโ€ task in the workspace. Use it just like any other file in your workspace.

To transfer a variable from one job to another

As I already mentioned, if you need only one IP address that you have as a variable at one time in the Assistant task, you simply send it to the Main task using Trigger / Call builds on other projects that You set the Assistant tasks in steps 3 and 4. In this case, you do not need any special configuration in the "Home" task.

  • Set up the Assistant task to automatically launch your โ€œmainโ€ task using the Trigger / Call assembly step on other projects . If you do not have this plugin, you can get it here
  • For build projects, enter the name of your main job
  • Click the Add Options button.
  • Select Predefined Options
  • Enter VarForMain=$VarFromHelper , where VarFromHelper is your VarFromHelper environment variable that contains your IP address, and VarForMain is the environment variable that will be set in your Basic job for this value. There is no reason why they cannot have the same name.

Now in your "main" task you can refer to $VarForMain , like any other environment variable

+7
source

The accepted answer didn't help me in my case, but I just came up with a trick:

  • Create the main task using the shell command

     echo "PARAMS_FILE=${WORKSPACE}/build-${BUILD_NUMBER}.params" > "${WORKSPACE}/build-${BUILD_NUMBER}.params" 
  • Create subtitles by adding them to the build steps (no steps after build)

  • Pass the file as a parameter source to substrings and update the file using a line in their scripts, for example:

     echo "MY_VAR=some_value" >> "$PARAMS_FILE" 

Thus, all subsequent tasks update the environment with the results of their predecessors.

+1
source

All Articles