<p>We install things in the <code>before_script</code> section of the <code>.gitlab-ci.yml</code> that way on every run of the runner we know what packages exist for each stage.</p>

CC BY-SA 4.0
2019-09-16T19:51:55.220Z
2019-09-16T19:51:55.220Z
Zachary
<p>I was thinking about a pipeline with the following steps:</p>

<ol>
<li>Install image dependencies (such as java, node, yarn and openssl)</li>
<li>Install node packages needed for the build</li>
<li>Install PMD</li>
<li>Do a code Analysis</li>
<li>Build</li>
<li>Deploy</li>
<li>Run tests on the server</li>
<li>Clean up</li>
</ol>

<p>But the issue here is that I require the tools installed on steps 1 and 2 for the rest of the build. There's a package that is used to run steps 5 to 7, for example, and OpenSSL is required to decrypt a server key in the repository (so GitLab can connect to the server).</p>

<p>I can't seem to find a way to persist Yarn's install through different stages. When the pipeline moves from stage 1 to stage 2, it will use yarn commands and will fail with the 127 error code (command not found), like this:</p>

<pre><code>$ yarn global add sfdx-cli
/bin/sh: eval: line 81: yarn: not found

ERROR: Job failed: exit code 127
</code></pre>

<p>Is it possible to persist the "environment setup" through all the stages? Can <code>artifacts</code> be used for this? If so, will I need to setup the commands for every stage? For example: Yarn might be installed in a folder which will be cached, but I need to point the 'yarn' command to the correct binary, right?</p>

<gitlab><cache>
Can I persist a Yarn install through different stages in a GitLab pipeline?
Renato Oliveira
# Can I persist a Yarn install through different stages in a GitLab pipeline?

(Asked by: username_0 on 2019-09-08)

I was thinking about a pipeline with the following steps:

Install image dependencies (such as java, node, yarn and openssl)
Install node packages needed for the build
Install PMD
Do a code Analysis
Build
Deploy
Run tests on the server
Clean up

But the issue here is that I require the tools installed on steps 1 and 2 for the rest of the build. There's a package that is used to run steps 5 to 7, for example, and OpenSSL is required to decrypt a server key in the repository (so GitLab can connect to the server).
I can't seem to find a way to persist Yarn's install through different stages. When the pipeline moves from stage 1 to stage 2, it will use yarn commands and will fail with the 127 error code (command not found), like this:
$ yarn global add sfdx-cli
/bin/sh: eval: line 81: yarn: not found

ERROR: Job failed: exit code 127

Is it possible to persist the "environment setup" through all the stages? Can artifacts be used for this? If so, will I need to setup the commands for every stage? For example: Yarn might be installed in a folder which will be cached, but I need to point the 'yarn' command to the correct binary, right?

**Tags:** gitlab, cache


---

## 1 answers

### Answer by username_1 on 2019-09-16. Score: 1

We install things in the `before_script` section of the `.gitlab-ci.yml` that way on every run of the runner we know what packages exist for each stage.


---

