在CI / CD管道中使用if-then else

时间:2020-01-15 06:18:24

标签: gitlab gitlab-ci gitlab-ci-runner

我目前正在尝试构建在gitlab中运行的CI / CD管道。我想建立一个管道,gitlab可以检查文件夹node_module是否已经在文件夹WebClient内,如果不是,则执行作业deploy_node_module,以及是否有任何更改文件夹WebClient,然后我将执行作业deploy_dev_client

目前,我的gitlab-ci.yml如下:

    deploy_node_module:
      stage: client
      tags:
        - my tags
      script:
        - '& cd WebClient'
        - powershell.exe -NoP -NonI -Command "Expand-Archive -Path node_modules.zip -DestinationPath ..\WebClient"
      rules:
        - exists:
          - node_modules
          when: never

    deploy_dev_client:
      stage: client
      tags:
        - my tags
      script:
        - '& cd WebClient'
        - 'npm rebuild node-sass'
        - 'npm install @angular/cli@7.0.3'
        - '& npm run build-release --max_old_space_size=$NODE_MEMORY_SIZE'

      rules:
        - changes:
          - WebClient/*
          when: always
        - when: on_success

我对管道的目标是在每个推送请求之后: 1.检查node_module内是否有WebClient 2.检查WebClient文件夹中的任何文件中是否有任何更改->如果为true,请运行作业

我尝试在gitlab-ci.yml中使用 if,然后,但是即使我在CI Lint上进行测试时未发现语法错误,该操作也没有通过:

deploy_dev_client:
  stage: client
  tags:
    - my tags
  script:
    - '& cd WebClient'
    - >
      if not exist node_modules;
        then powershell.exe -NoP -NonI -Command "Expand-Archive -Path node_modules.zip -DestinationPath ..\WebClient";
      else echo existing node_modules; 
      fi
    - 'npm rebuild node-sass'
    - 'npm install @angular/cli@7.0.3'
    - '& npm run build-release --max_old_space_size=$NODE_MEMORY_SIZE'

  rules:
    - changes:
      - WebClient/*
      when: always
    - when: on_success

0 个答案:

没有答案