Halil
Halil

Reputation: 1

GitLab pipeline (.gitlab-ci.yml) for CI and scheduled SAST

We would like to have a .gitlab-ci.yml which supports the default CI pipeline and the SAST pipeline only scheduled once a day.

What seems logic but didn't work is this configuration:

include:
  - template: Security/SAST.gitlab-ci.yml
  - template: Workflows/MergeRequest-Pipelines.gitlab-ci.yml

image: node:lts-alpine

stages:
  - lint
  - build
  - test

lint:
  stage: lint
  script:
    - npm i
    - npm run lint

build:
  stage: build
  script:
    - npm i
    - npm run build

test-unit:
  stage: test
  script:
    - npm i
    - npm run test:unit

test-sast:
  stage: test
  script: [ "true" ]
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
      when: always
    - when: never

Then did some tests using the environment variable SAST_DISABLED which didn't work as well.

May be someone has a similiar setup and may help out with a working sample?

Upvotes: 0

Views: 1344

Answers (1)

virgilwashere
virgilwashere

Reputation: 3

Your workflow:rules do not have an explicit allow for $CI_PIPELINE_SOURCE == "schedule"

This is what I use for merge request pipelines:

workflow:
  rules:
    # Do not start pipeline for WIP/Draft commits
    - if: $CI_COMMIT_TITLE =~ /^(WIP|Draft)/i
      when: never
    
    # MergeRequest-Pipelines workflow
    # For merge requests create a pipeline.
    - if: $CI_MERGE_REQUEST_IID || $CI_PIPELINE_SOURCE == "merge_request_event"
    
    # For tags, create a pipeline.
    - if: $CI_COMMIT_TAG
    # For default branch create a pipeline (this includes on schedules, pushes, merges, etc.).
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

    # For other pipeline triggers
    - if: $CI_PIPELINE_SOURCE =~ /^trigger|pipeline|web|api$/

Upvotes: 0

Related Questions