I'm trying to build an application using GitLab CI.
The name of the generated file is depending on the time, in this format
DEV_APP_yyyyMMddhhmm
(example: DEV_APP_201810221340, corresponding to the date of today 2018/10/22 13h40).
How can I store this name in a global variable inside the .gitlab-ci.yml file?
Here is my .gitlab-ci.yml file:
image: docker:latest
image: docker:latest
services:
- docker:dind
variables:
  DOCKER_DRIVER: overlay
  SPRING_PROFILES_ACTIVE: gitlab-ci
#   TIME: ""
#  BRANCH: ""
#  REC_BUILD_NAME: ""
  TIME: "timex"
  BRANCH: "branchx"
  DEV_BUILD_NAME: "DEV_APP_x"
stages:
- preparation
- build
- package
- deploy
- manual_rec_build
- manual_rec_package
job_preparation:
  stage: preparation
  script:
  - echo ${TIME}
  - export TIME=$(date +%Y%m%d%H%M)
  - "BRANCH=$(echo $CI_BUILD_REF_SLUG | sed 's/[^[[:alnum:]]/_/g')"
  - "DEV_BUILD_NAME=DEV_APP_${BRANCH}_${TIME}"
  - echo ${TIME}
maven-build:
  image: maven:3-jdk-8
  stage: build
  script:
  - echo ${TIME}
  - "mvn package -B"
  artifacts:
paths:
    - target/*.jar
  only:
  - merge-requests
  - /^feature\/sprint.*$/
  - /^DEV_.*$/
#  when: manual
docker-build:
  stage: package
  script:
  - echo ${TIME}
  - docker build -t registry.gitlab.com/mourad.sellam/actuator-simple .
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
  - docker push registry.gitlab.com/mourad.sellam/actuator-simple
  only:
  - merge-requests
  - /^feature\/sprint.*$/
  - /^DEV_.*$/
  when: manual
    k8s-deploy-production:
  image: google/cloud-sdk
  stage: deploy
  script:
  - echo ${TIME}
  - echo "$GOOGLE_KEY" > key.json
  - gcloud auth activate-service-account --key-file key.json
  - gcloud config set compute/zone europe-west1-c
  - gcloud config set project actuator-sample
  - gcloud config set container/use_client_certificate True
  - gcloud container clusters get-credentials actuator-example
  - kubectl delete secret registry.gitlab.com
  - kubectl create secret docker-registry registry.gitlab.com --docker-server=https://registry.gitlab.com --docker-username=myUserName--docker-password=$REGISTRY_PASSWD --docker-email=myEmail@gmail.com
  - kubectl apply -f deployment.yml --namespace=production
  environment:
    name: production
    url: https://example.production.com
  when: manual
job_manual_rec_build:
  image: maven:3-jdk-8
  stage: manual_rec_build
  script:
  - echo ${TIME}
  - "mvn package -B"
  artifacts:
    paths:
    - target/*.jar
  when: manual
    #   allow_failure: false
job_manual_rec_package:
  stage: manual_rec_package
  variables:
  script:
    - echo ${TIME}
  - echo ${DEV_BUILD_NAME}
  - docker build -t registry.gitlab.com/mourad.sellam/actuator-simple:${DEV_BUILD_NAME} .
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker push registry.gitlab.com/mourad.sellam/actuator-simple
  artifacts:
    paths:
    - target/*.jar
  when: on_success
  #test 1
When I call
echo ${TIME}
It displays "timex".
Could you tell me how to store a global variable and set it in each job?