diff --git a/.generated-pipeline.yml b/.generated-pipeline.yml new file mode 100644 index 000000000..d11d33b1a --- /dev/null +++ b/.generated-pipeline.yml @@ -0,0 +1,11 @@ +stages: + - placeholder + +# We need a placeholder success job because we can't trigger empty pipelines +# Can be replaced by a useful gitlab job to run on non-PR commits +success_job: + stage: placeholder + tags: ["arch:amd64"] + image: registry.ddbuild.io/ci/datadog-agent-buildimages/deb_x64:v48815877-9bfad02c + script: + - echo SUCCESS diff --git a/.gitlab-ci-agent-build.yml b/.gitlab-ci-agent-build.yml new file mode 100644 index 000000000..de5ac400f --- /dev/null +++ b/.gitlab-ci-agent-build.yml @@ -0,0 +1,103 @@ +include: "https://gitlab-templates.ddbuild.io/slack-notifier/v3-sdm/template.yml" + +stages: + - test + - after-test + - check-downstream + - notify + +# We're using two anchors because Gitlab doesn't allow us to use multiple anchors inside of a rules field. +.skip_stable_branches: &skip_stable_branches + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + when: never + - if: $CI_COMMIT_BRANCH =~ /^7.[0-9]{2}.x/ + when: never + - if: $CI_COMMIT_TAG != null + when: never + - changes: + - "**/*.rb" + - Rakefile + - omnibus-software.gemspec + - Gemfile + - .gitlab* + - .generated-pipeline.yml + - .gitlab-ci-agent-build.yml + when: always + +.on_success_skip_stable_branches: &on_success_skip_stable_branches + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + when: never + - if: $CI_COMMIT_BRANCH =~ /^7.[0-9]{2}.x/ + when: never + - if: $CI_COMMIT_TAG != null + when: never + - changes: + - "**/*.rb" + - Rakefile + - omnibus-software.gemspec + - Gemfile + - .gitlab* + - .generated-pipeline.yml + - .gitlab-ci-agent-build.yml + when: on_success + +trigger-agent-build: + rules: + - *skip_stable_branches + - when: never + stage: test + trigger: + project: datadog/datadog-agent + strategy: depend + variables: + OMNIBUS_SOFTWARE_VERSION: $CI_COMMIT_BRANCH + RUN_ALL_BUILDS: "true" + RUN_KITCHEN_TESTS: "true" + +on_success: + rules: + - *on_success_skip_stable_branches + - when: always + stage: after-test + needs: + - job: "trigger-agent-build" + optional: true + tags: ["arch:amd64"] + image: registry.ddbuild.io/ci/datadog-agent-buildimages/deb_x64:v48815877-9bfad02c + script: + - echo success > output.pipeline + artifacts: + paths: + - output.pipeline + expire_in: 1 week + +# This job is monitored on github and acts as a required check. +# A few details on the setup: +# We can't monitor a trigger job from github, it has to have a script section. +# We need the monitored job to fail if the downstream pipeline failed, and succeed if +# the downstream pipeline succeeded. If the job is skipped, it isn't taken into account +# on github. +# This is where the on_success job kicks in. It run only if the previous job completes +# and writes `success` in a file that's fetched by the `check-downstream-pipeline` job. +# This allows us to have the check-downstream-pipeline to always run while replicating +# the status of the downstream pipeline. +check-downstream-pipeline: + rules: + - *skip_stable_branches + - when: always + stage: check-downstream + tags: ["arch:amd64"] + image: registry.ddbuild.io/ci/datadog-agent-buildimages/deb_x64:v48815877-9bfad02c + script: + - cat output.pipeline + +notify: + extends: .slack-notifier-base + stage: notify + dependencies: [] + rules: + - *skip_stable_branches + - when: never + script: | + export MESSAGE="Your omnibus-software test pipeline completed" + /usr/local/bin/notify.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 302ad8568..abd52e752 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,97 +1,37 @@ -include: "https://gitlab-templates.ddbuild.io/slack-notifier/v3-sdm/template.yml" - stages: - - test - - after-test - - check-downstream - - notify - -# We're using two anchors because Gitlab doesn't allow us to use multiple anchors inside of a rules field. -.skip_stable_branches: &skip_stable_branches - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: never - - if: $CI_COMMIT_BRANCH =~ /^7.[0-9]{2}.x/ - when: never - - if: $CI_COMMIT_TAG != null - when: never - - changes: - - "**/*.rb" - - Rakefile - - omnibus-software.gemspec - - Gemfile - when: always + - generation + - trigger -.on_success_skip_stable_branches: &on_success_skip_stable_branches - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: never - - if: $CI_COMMIT_BRANCH =~ /^7.[0-9]{2}.x/ - when: never - - if: $CI_COMMIT_TAG != null - when: never - - changes: - - "**/*.rb" - - Rakefile - - omnibus-software.gemspec - - Gemfile - when: on_success - -trigger-agent-build: - rules: - - *skip_stable_branches - - when: never - stage: test - trigger: - project: datadog/datadog-agent - strategy: depend - variables: - OMNIBUS_SOFTWARE_VERSION: $CI_COMMIT_BRANCH - RUN_ALL_BUILDS: "true" - RUN_KITCHEN_TESTS: "true" - -on_success: - rules: - - *on_success_skip_stable_branches - - when: always - stage: after-test - needs: - - job: "trigger-agent-build" - optional: true +check_if_branch_is_a_pr: + stage: generation tags: ["arch:amd64"] image: registry.ddbuild.io/ci/datadog-agent-buildimages/deb_x64:v48815877-9bfad02c - script: - - echo success > output.pipeline + allow_failure: true + script: | + cp .generated-pipeline.yml generated-pipeline.yml + # Check if our current branch is inside the PR list of omnibus-software + curl https://api.github.com/repos/DataDog/omnibus-software/pulls + if curl https://api.github.com/repos/DataDog/omnibus-software/pulls | grep "$CI_COMMIT_REF_NAME" + then + echo "Current commit is on a PR" + cp .gitlab-ci-agent-build.yml generated-pipeline.yml + else + echo "Current commit is not on a PR" + fi artifacts: + untracked: true + expire_in: 1h paths: - - output.pipeline - expire_in: 1 week + - generated-pipeline.yml + +trigger_pipeline: + stage: trigger + needs: + - job: check_if_branch_is_a_pr + artifacts: true + trigger: + include: + - artifact: generated-pipeline.yml + job: check_if_branch_is_a_pr -# This job is monitored on github and acts as a required check. -# A few details on the setup: -# We can't monitor a trigger job from github, it has to have a script section. -# We need the monitored job to fail if the downstream pipeline failed, and succeed if -# the downstream pipeline succeeded. If the job is skipped, it isn't taken into account -# on github. -# This is where the on_success job kicks in. It run only if the previous job completes -# and writes `success` in a file that's fetched by the `check-downstream-pipeline` job. -# This allows us to have the check-downstream-pipeline to always run while replicating -# the status of the downstream pipeline. -check-downstream-pipeline: - rules: - - *skip_stable_branches - - when: always - stage: check-downstream - tags: ["arch:amd64"] - image: registry.ddbuild.io/ci/datadog-agent-buildimages/deb_x64:v48815877-9bfad02c - script: - - cat output.pipeline -notify: - extends: .slack-notifier-base - stage: notify - dependencies: [] - rules: - - *skip_stable_branches - - when: never - script: | - export MESSAGE="Your omnibus-software test pipeline completed" - /usr/local/bin/notify.sh