E
E
emashev2019-02-18 14:17:47
GitLab
emashev, 2019-02-18 14:17:47

How to configure deploy in gitlab-ci by variable?

Greetings, is it possible to somehow run a CI task in gitlab, only on a schedule and only from the master? At the same time, do not run the task when committing to the master?
If I write:

only:
      refs:
      - master
      - schedules

then the task is launched both at commits to the master and through the scheduler.
I read in the documentation that you can set variables, and the task will only run if they are defined.
I set the DEPLOY variable to cron in shedules, but the task does not start.
---
stages:
- prod_deploy

variables:
    GITLAB_INT: gitlab01

cron_deploy:
    stage: prod_deploy
    only:
      refs:
      - master
      - schedules
      variables:
      - $DEPLOY == "cron"
    except:
      changes:
      - .gitlab-ci.yml
    tags:
    - PROD_CRON
    before_script:
    # Удаляем старую версию 
    - rm -f ${PROD_SRC}/htdocs_2.tar
    # Перемещаем предыдущую версию
    - mv ${PROD_SRC}/htdocs_1.tar ${PROD_SRC}/htdocs_2.tar || echo "Файла еще нет"
    - tar -cpf ${PROD_SRC}/htdocs_1.tar ${PROD_SRC}/htdocs
    script:
    - cd ${PROD_SRC}/htdocs && git reset --hard HEAD^
    - cd ${PROD_SRC}/htdocs && git checkout ${CI_COMMIT_REF_NAME} && git pull
    when: always

Or will these variables not work the way I want?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Redleks, 2019-06-12
@emashev

$DEPLOY == "cron"I don't think variables are set this way.
You have the above variable set correctly:
DEPLOY: "cron"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question