Upload artifacts with parallelism

Hello there,

I have a job which runs with parallelism: 4. It performs unit testing, so I would like to upload the coverage as artifacts. My issue is that artifacts are being uploaded by each parallel run, which means I have the same artifacts uploaded 4 times.

It’s said in this documentation that I can use CIRCLE_NODE_INDEX to upload artifacts only for one parallel run. I tried that, but as said in this forum post, conditions are evaluated when the Circle CI config file is compiled, and environment variables are evaluated at runtime, so checking for CIRCLE_NODE_INDEX this way won’t work.

Does someone have a solution for this ?

Thanks in advance for your help

You can use the environment variable to decide if you wish to create the artefacts - or to decide if you want to delete the info before the store_artifacts step.

How would you do this ? Doing something like this won’t work :

        description: 'Store global coverage report in artifacts'
                default: CIRCLE_NODE_INDEX
                type: env_var_name
            - when:
                      equal: [0, << parameters.node_index >>]
                      - store_artifacts:
                            path: coverage

because when the when instructions is evaluated, environment variables aren’t yet

You would do the checking and file processing within a run step as the shell does know about the environment variable. The result would be that the store-artifacts command would always execute, but there may not be any files for it to store.

I’ve never done this, and the docs are not clear on what happens when the path given to store-artifacts is empty or does not exist.