<p>One option is to <a href="https://docs.gitlab.com/ee/ci/variables/#pass-an-environment-variable-to-another-job" rel="nofollow noreferrer">inherit your environment variable</a> from another job. You can create two different jobs, one to create the environment variable, and one to trigger the local CI pipeline.</p>
<p>Once all that is done, you should have something like this:</p>
<pre><code>stages:
  - build
  - deploy

nightlies_env:
  stage: build
  variables:
    BUILD_NAME: &quot;nightly&quot;
  script:
    - BUILD_NAME=&quot;${BUILD_NAME}-$(date +&quot;%Y%m%d&quot;)&quot;
    - echo &quot;BUILD_NAME=$BUILD_NAME&quot; &gt;&gt; build.env
  artifacts:
    reports:
      dotenv: build.env

nightlies:
  stage: deploy
  variables:
    BUILD_NAME: $BUILD_NAME
  trigger:
    include: build.yml
    strategy: depend
</code></pre>

CC BY-SA 4.0
2021-05-20T16:09:09.630Z
That also doesn't work: `Syntax is incorrect. CI configuration validated, including all configuration added with the includes keyword`. It's saying that it doesn't recognise the `dependencies` key.
user1092809
CC BY-SA 4.0
2021-05-20T19:37:45.043Z
@user1092809 I've modified the question to not include the dependencies keyword. You're correct, dependencies isn't friendly with the trigger keyword :) The above solution passes the env. variable w/o using dependencies. Technically in this case, dependencies isn't a requirement, as artifacts are by default passed between stages in GitLab. Using dependencies is just a method for explicitly declaring specific stages to inherit artifacts from.
Preston Martin
CC BY-SA 4.0
2021-05-20T15:54:14.003Z
2021-05-20T19:34:33.810Z
2021-05-20T19:34:33.810Z
Preston Martin
<p>I have a job which needs to include another job and needs to append a value to a variable, such as:</p>
<pre><code>nightlies:
  variables:
    BUILD_NAME: &quot;nightly&quot;

  script:
    - $BUILD_NAME=&quot;${BUILD_NAME}-$(date +&quot;%Y%m%d&quot;)&quot;

  only:
    - schedules

  trigger:
    include:
      - local: /.gitlab-ci/build.yml
    strategy: depend
</code></pre>
<p>However reading the documentation <code>script</code> and <code>trigger</code> cannot be used together and I'm unsure of how else to create the <code>BUILD_NAME</code> with a date. Is there a way to use both. Otherwise, is there a way I could remove the trigger in order to use script, which would still call that job?</p>

CC BY-SA 4.0
2021-05-20T16:16:08.847Z
another option I explored was using `before_script`, in the root of the file, but it seems that the variable made there cannot be exported and I have no idea how else to make it accessible to the `BUILD_NAME` variable
user1092809
<gitlab><builds>
How to use script in a Gitlab bridge job?
user1092809
# How to use script in a Gitlab bridge job?

(Asked by: username_0 on 2021-05-20)

I have a job which needs to include another job and needs to append a value to a variable, such as:
nightlies:
  variables:
    BUILD_NAME: "nightly"

  script:
    - $BUILD_NAME="${BUILD_NAME}-$(date +"%Y%m%d")"

  only:
    - schedules

  trigger:
    include:
      - local: /.gitlab-ci/build.yml
    strategy: depend

However reading the documentation script and trigger cannot be used together and I'm unsure of how else to create the BUILD_NAME with a date. Is there a way to use both. Otherwise, is there a way I could remove the trigger in order to use script, which would still call that job?

**Tags:** gitlab, builds

> **Comments:**
> **username_0**: another option I explored was using `before_script`, in the root of the file, but it seems that the variable made there cannot be exported and I have no idea how else to make it accessible to the `BUILD_NAME` variable  

---

## 1 answers

### Answer by username_1 on 2021-05-20. Score: 1

One option is to inherit your environment variable from another job. You can create two different jobs, one to create the environment variable, and one to trigger the local CI pipeline.
Once all that is done, you should have something like this:
stages:
  - build
  - deploy

nightlies_env:
  stage: build
  variables:
    BUILD_NAME: "nightly"
  script:
    - BUILD_NAME="${BUILD_NAME}-$(date +"%Y%m%d")"
    - echo "BUILD_NAME=$BUILD_NAME" >> build.env
  artifacts:
    reports:
      dotenv: build.env

nightlies:
  stage: deploy
  variables:
    BUILD_NAME: $BUILD_NAME
  trigger:
    include: build.yml
    strategy: depend

> **Comments:**
> **username_0**: That also doesn't work: `Syntax is incorrect. CI configuration validated, including all configuration added with the includes keyword`. It's saying that it doesn't recognise the `dependencies` key.  
> **username_1**: @username_0 I've modified the question to not include the dependencies keyword. You're correct, dependencies isn't friendly with the trigger keyword :) The above solution passes the env. variable w/o using dependencies. Technically in this case, dependencies isn't a requirement, as artifacts are by default passed between stages in GitLab. Using dependencies is just a method for explicitly declaring specific stages to inherit artifacts from.  

---

