Newer
Older
# --------------------------------------------------------------------------------------
# Global
# --------------------------------------------------------------------------------------
include:
- local: common.yml
stages:
- retrigger
workflow:
rules:
# Explicitly allow externally triggered pipelines in every case
- if: $CI_PIPELINE_SOURCE == "api"
- if: $CI_PIPELINE_SOURCE == "pipeline"
- if: $CI_PIPELINE_SOURCE == "web"
# Do not run pipelines for merge requests
- if: $CI_MERGE_REQUEST_IID
when: never
# Do not run pipelines on forked projects
# (use id instead of name because of rename)
- if: $CI_PROJECT_ID != $MANIFEST_PROJECT_ID
when: never
# Do not run pipelines on integration branches
- if: $CI_COMMIT_REF_NAME =~ /^integrate\/.*/
when: never
# In all other cases, run the pipeline automatically
- when: always
.full_build_pipeline:
rules:
# Run the full build pipeline on non-master branches (i.e. in the merge request)
# or if explicitly triggered by the API or the web button.
- if: $CI_COMMIT_REF_NAME != $MASTER_BRANCH_MANIFEST
- if: $CI_PIPELINE_SOURCE == "api"
- if: $CI_PIPELINE_SOURCE == "pipeline"
- if: $CI_PIPELINE_SOURCE == "web"
.short_master_pipeline:
rules:
# The short master pipeline does not execute a full build, but only mirrors the
# build result from the merge request. Run it on the master branch per default if
# not explicitly triggered.
- if: $CI_PIPELINE_SOURCE == "api"
when: never
- if: $CI_PIPELINE_SOURCE == "pipeline"
when: never
- if: $CI_PIPELINE_SOURCE == "web"
when: never
- if: $CI_COMMIT_REF_NAME == $MASTER_BRANCH_MANIFEST
# --------------------------------------------------------------------------------------
# Stage: retrigger
# --------------------------------------------------------------------------------------
retrigger:
extends:
- .infrastructure
- .short_master_pipeline
stage: retrigger
script:
- PROJECTS=$(
.gitlab-ci/scripts/get_manifest_projects.py
--manifest=default.xml
--remote=${CI_PARAM_SECO_REMOTE}
--concat-namespaces
)
# Add the gitlab-ci project
- PROJECTS="$PROJECTS ${CI_PROJECT_ROOT_NAMESPACE}/yocto/infrastructure/gitlab-ci"
# TODO retrigger gitlab-ci integration also
# Retrigger also project in SRCREV
- echo -e "Projects:\n${PROJECTS}"
- for PROJECT in ${PROJECTS}; do
.gitlab-ci/scripts/retrigger_mr_pipeline_jobs.py
--gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN}
--project=${PROJECT}
--state=opened
--target-branch=${MASTER_BRANCH_MANIFEST}
--job=check
;
done
# --------------------------------------------------------------------------------------
# Stage: infrastructure
# --------------------------------------------------------------------------------------
generate-build-jobs:
extends:
- .infrastructure
- .full_build_pipeline
# The job generation script implicitly passes the OS environment to the template, so
# that the template has access to all GitLab CI variables. Hence there is no need
# to explicitly pass any of them as command line arguments.
- .gitlab-ci/scripts/generate_job_from_template.py
--template=.gitlab-ci/${BUILD_JOBS_TEMPLATE}
> build-jobs.yml
artifacts:
expire_in: 4 weeks
- build-jobs.yml
trigger-build-jobs:
extends:
- .full_build_pipeline
stage: infrastructure
needs: ["generate-build-jobs"]
trigger:
include:
- artifact: build-jobs.yml
job: generate-build-jobs
strategy: depend
extends:
- .full_build_pipeline
- .yamllint
# --------------------------------------------------------------------------------------
# Stage: build
# --------------------------------------------------------------------------------------
build:merge_request:
extends:
- .infrastructure
- .short_master_pipeline
# For some reason we cannot use a variable for the timeout, the CI linter reports
# 'jobs:build:merge_request:timeout config should be a duration' then.
# Hence we use GitLab's 'reference' syntax instead.
timeout: !reference [variables, BUILD_TIMEOUT]
script:
- cd ${CI_PROJECT_DIR}
# Get pipeline for merge request
- MR_PIPELINE=$(.gitlab-ci/scripts/get_pipelines.py
--gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN}
--project=${CI_PROJECT_PATH}
--commit=${CI_COMMIT_SHA}
--ref=^${MASTER_BRANCH_MANIFEST} || true | head -1)
# If pipeline exists, mirror its result
- if [ ! -z "${MR_PIPELINE}" ]; then
.gitlab-ci/scripts/mirror_pipeline_result.py
--gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN}
--project=${CI_PROJECT_PATH}
--pipeline=${MR_PIPELINE}
# If no pipeline found, trigger a new one on the master
- else
.gitlab-ci/scripts/trigger_pipeline.py
--gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN}
--project=${CI_PROJECT_PATH}
--ref=${MASTER_BRANCH_MANIFEST}
- fi