How to use script in a Gitlab bridge job?
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: &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