I’m wanting to set up a generic pipeline that can execute, or trigger, a different pipeline depending on some conditions. I’ve tried various scenarios with no success. Here is a synopsis of what I am trying:
I have a file called project-info.yml containing:
##########
variables:
GITLAB_CI_YML: “gitlab-ci_java_build_deploy_only.yml”
PROJECT_LANG" “JAVA”
##########
My .gitlab-ci.yml contains:
##########
include: “project-info.yml”
script:
- ‘echo “INFO: CI_COMMIT_BRANCH: ${CI_COMMIT_BRANCH}”’
- ‘echo “INFO: PROJECT_LANG: ${PROJECT_LANG}”’
- |
if [ $CI_COMMIT_BRANCH == “MAIN” ]; then
if [ $PROJECT_LANG == “JAVA” ]; then
GITLAB_CI_YML=“gitlab-ci_java_full_build.yml”
elif [ $PROJECT_LANG == “Python” ]; then
GITLAB_CI_YML=“gitlab-ci_python_full_build.yml”
fi
fi
- ‘echo “INFO: GITLAB_CI_YML: ${GITLAB_CI_YML}”’
trigger: $GITLAB_CI_YML
##########
Any recommendations on how to accomplish this?
Thank you
Can’t you just code gitlab-ci_python_full_build.yml
, gitlab-ci_java_full_build.yml
, and gitlab-ci_java_build_deploy_only.yml
in your .gitlab-ci.yml
with rules to trigger each?
workflow:
rules:
- if: $CI_COMMIT_BRANCH == "MAIN" && $PROJECT_LANG == “JAVA”
See GitLab CI/CD `workflow` keyword | GitLab
Hi derek-mba,
Sorry for the slow response. The issue I’m having is not with the if, but with triggering or including a secondary YAML from .gitlab-ci.yml. Here is what I have, it validates successful in the CI LINT, it initiates the child-pipeline, but it fails with “Include '{“local”:”" needs to match exactly one accessor!" whcn I check it in and run it in the gitlab runner.
before-script:
- echo “INFO: Begin gitlab-ci.yml”
include ‘project-info.yml’
decide_pipeline:
script:
- ‘echo “INFO: CI_COMMIT_BRANCH: ${CI_COMMIT_BRANCH}”’
- ‘echo “INFO: PROJECT_LANG: ${PROJECT_LANG}”’
- |
if [ $CI_COMMIT_BRANCH == “MAIN” ]; then
if [ $PROJECT_LANG == “python” ]; then
GITLAB_CI_YML=“gitlab-ci-python-full-build.yml”
elif [ $PROJECT_LANG == “java” ]; then
GITLAB_CI_YML=“gitlab-ci-java-full-build.yml”
fi
elif [ $GITLAB_CI_YML == “” ; then
GITLAB_CI_YML=“gitlab-ci-build-and-deploy_only.yml”
fi
- ‘echo “INFO: GITLAB_CI_YML: ${GITLAB_CI_YML}”’
trigger_pipeline:
trigger:
include: $GITLAB_CI_YML
strategy: depend