Copy file/files from One Jenkins job to another Jenkins job

Venkata
4 min readMay 12, 2023

Jenkins is one of the most popular open-source process automation tools. If you are building automation to improve your software application development and delivery process, consider CI/CD system. Jenkins can help in many ways to address your CI/CD needs.

Today I am going to share how you can use a specific file that is part of one Jenkins job in another Jenkins job. If you are running a single node (only primary instance), you don’t need to worry about it, as you can pick up the file from the workspace of another job using the absolute path. In a real work environment, there might be more Jenkins instances, and each Jenkins instance might have more than one secondary node. In this case, it becomes hard for individuals to copy the file.

Jenkins can do this without worrying about which node has that file. I will explain this with specific examples.

We have a Jenkins job that generates test data (let’s call it data_generator); there is another Jenkins job that needs to validate information based on this test data (Let’s call it run_functional_test — this will test automation ). In this process, we need information about the data generated, like transaction ID and transaction amount, to validate whether this information is accurate from the regular test activity.

Note: You might be wondering why we need to use data_generation separately. Why don’t we generate data using the same test automation? There are different reasons. This generated data is consumed by functional test automation and other automation scripts for additional testing and development activities.

While generating test data data_generator job dumps some log files with the required information; run_functional_test Jenkins job.

In the data_generator Jenkins job, go to Project configuration (Jenkins job data_generator configuration) Office 365 Connector > Permission to Copy Artifact > In this section, select the check mark and add projects that are allowed to copy the artifacts. You can have more projects (Jenkins job names) in the screenshot below; we added permissions for the run_functional_test Jenkins job.

Now from the run_functional_test Jenkins job, we need to copy the artifacts from the data_generator Jenkins job. In the run_functional_test Jenkins job, go to the Build stage and select Copy artifacts from another project from the drop-down list. Now in this section, fill in the details, such as the Project name: (from which project you wanted to copy the artifacts).

Which build: select the option that is appropriate for your case; I recommend Copy from WORKSPACE of the latest complete build; in the use case mentioned above, the data file gets generated only when the data_generation Jenkins job is completed successfully, and also I always wanted to use latest data information for run_functional_test.

Artifacts to copy: you can provide a list of artifacts that needs to be copied from the data_generator workspace to the current project (run_funactional_test). You can give full path from space (for example, ./test/data.json, test directory is one of the folders in the workspace)

Target Director: if you want to copy the artifacts to a specific location in your current workspace (run_functional_test workspace). If you don’t give any value here by default, ./test/data.json (in this example) gets copied to workspace ./test/data.json

Once you update configurations, click save to ensure both Jenkins job configurations are saved. Now run the data_generator 1st and then run_functional_test. Once this is done, you can see the ./test/data.json file in the run_functional_test workspace. If you want to trigger run_functional_test right after the successful run of data_generator, then use the option Post-build Actions (the following screenshot gives you an idea, I am not covering details about this now). By configuring this setup, you will automatically trigger run_functional_test whenever data_generation is successful.

Automation can help us in many different ways during our work; this can help us get some work-life balance and also help us speed up our tasks. Significantly processes can improve individual as well as overall team productivity.

You can find additional detailed documentation from https://plugins.jenkins.io/parameterized-trigger/

--

--

Venkata

I believe in learning and sharing the knowledge, I write blogs related to nutrition, environment and Financial Independence.