tasks/pipeline.py
def run(
    ctx,
    git_ref=None,
    here=False,
    use_release_entries=False,
    major_versions='6,7',
    repo_branch="nightly",
    deploy=False,
    all_builds=True,
    kitchen_tests=True,
):
    """
    Run a pipeline on the given git ref (--git-ref <git ref>), or on the current branch if --here is given.
    By default, this pipeline will run all builds & tests, including all kitchen tests, but is not a deploy pipeline.
    Use --deploy to make this pipeline a deploy pipeline, which will upload artifacts to the staging repositories.
    Use --no-all-builds to not run builds for all architectures (only a subset of jobs will run. No effect on pipelines on the default branch).
    Use --no-kitchen-tests to not run all kitchen tests on the pipeline.

    By default, the nightly release.json entries (nightly and nightly-a7) are used.
    Use the --use-release-entries option to use the release-a6 and release-a7 release.json entries instead.

    By default, the pipeline builds both Agent 6 and Agent 7.
    Use the --major-versions option to specify a comma-separated string of the major Agent versions to build
    (eg. '6' to build Agent 6 only, '6,7' to build both Agent 6 and Agent 7).

    The --repo-branch option indicates which branch of the staging repository the packages will be deployed to (useful only on deploy pipelines).

    If other pipelines are already running on the git ref, the script will prompt the user to confirm if these previous
    pipelines should be cancelled.

    Examples
    Run a pipeline on my-branch:
      inv pipeline.run --git-ref my-branch

    Run a pipeline on the current branch:
      inv pipeline.run --here

    Run a pipeline without kitchen tests on the current branch:
      inv pipeline.run --here --no-kitchen-tests

    Run a deploy pipeline on the 7.32.0 tag, uploading the artifacts to the stable branch of the staging repositories:
      inv pipeline.run --deploy --use-release-entries --major-versions "6,7" --git-ref "7.32.0" --repo-branch "stable"
    """

    project_name = "DataDog/datadog-agent"
    gitlab = Gitlab(project_name=project_name, api_token=get_gitlab_token())
    gitlab.test_project_found()

    if not git_ref and not here:
        raise Exit("Either --here or --git-ref <git ref> must be specified.", code=1)

    if use_release_entries:
        release_version_6 = release_entry_for(6)
        release_version_7 = release_entry_for(7)
    else:
        release_version_6 = nightly_entry_for(6)
        release_version_7 = nightly_entry_for(7)

    major_versions = major_versions.split(',')
    if '6' not in major_versions:
        release_version_6 = ""
    if '7' not in major_versions:
        release_version_7 = ""

    if here:
        git_ref = ctx.run("git rev-parse --abbrev-ref HEAD", hide=True).stdout.strip()

    if deploy:
        # Check the validity of the deploy pipeline
        check_deploy_pipeline(gitlab, git_ref, release_version_6, release_version_7, repo_branch)
        # Force all builds and kitchen tests to be run
        if not all_builds:
            print(
                color_message(
                    "WARNING: ignoring --no-all-builds option, RUN_ALL_BUILDS is automatically set to true on deploy pipelines",
                    "orange",
                )
            )
            all_builds = True
        if not kitchen_tests:
            print(
                color_message(
                    "WARNING: ignoring --no-kitchen-tests option, RUN_KITCHEN_TESTS is automatically set to true on deploy pipelines",
                    "orange",
                )
            )
            kitchen_tests = True

    pipelines = get_running_pipelines_on_same_ref(gitlab, git_ref)

    if pipelines:
        print(
            f"There are already {len(pipelines)} pipeline(s) running on the target git ref.",
            "For each of them, you'll be asked whether you want to cancel them or not.",
            "If you don't need these pipelines, please cancel them to save CI resources.",
            "They are ordered from the newest one to the oldest one.\n",
            sep='\n',
        )
        cancel_pipelines_with_confirmation(gitlab, pipelines)

    try:
        pipeline_id = trigger_agent_pipeline(
            gitlab,
            git_ref,
            release_version_6,
            release_version_7,
            repo_branch,
            deploy=deploy,
            all_builds=all_builds,
            kitchen_tests=kitchen_tests,
        )
    except FilteredOutException:
        print(color_message(f"ERROR: pipeline does not match any workflow rule. Rules:\n{workflow_rules()}", "red"))
        return

    wait_for_pipeline(gitlab, pipeline_id)

    Run a pipeline on the given git ref (--git-ref <git ref>), or on the current branch if --here is given.
    By default, this pipeline will run all builds & tests, including all kitchen tests, but is not a deploy pipeline.
    Use --deploy to make this pipeline a deploy pipeline, which will upload artifacts to the staging repositories.
    Use --no-all-builds to not run builds for all architectures (only a subset of jobs will run. No effect on pipelines on the default branch).
    Use --no-kitchen-tests to not run all kitchen tests on the pipeline.

    By default, the nightly release.json entries (nightly and nightly-a7) are used.
    Use the --use-release-entries option to use the release-a6 and release-a7 release.json entries instead.

    By default, the pipeline builds both Agent 6 and Agent 7.
    Use the --major-versions option to specify a comma-separated string of the major Agent versions to build
    (eg. '6' to build Agent 6 only, '6,7' to build both Agent 6 and Agent 7).

    The --repo-branch option indicates which branch of the staging repository the packages will be deployed to (useful only on deploy pipelines).

    If other pipelines are already running on the git ref, the script will prompt the user to confirm if these previous
    pipelines should be cancelled.

    Examples
    Run a pipeline on my-branch:
      inv pipeline.run --git-ref my-branch

    Run a pipeline on the current branch:
      inv pipeline.run --here

    Run a pipeline without kitchen tests on the current branch:
      inv pipeline.run --here --no-kitchen-tests

    Run a deploy pipeline on the 7.32.0 tag, uploading the artifacts to the stable branch of the staging repositories:
      inv pipeline.run --deploy --use-release-entries --major-versions "6,7" --git-ref "7.32.0" --repo-branch "stable"
    


By default, the nightly release.json entries (nightly and nightly-a7) are used.

By default, the pipeline builds both Agent 6 and Agent 7.
Use the --major-versions option to specify a comma-separated string of the major Agent versions to build
.

-repo-branch option indicates which branch of the staging repository the packages will be deployed to (useful only on deploy pipelines).

If other pipelines are already running on the git ref, the script will prompt the user to confirm if these previous
pipelines should be cancelled.



Run a pipeline on the current branch:
inv pipeline.run --here




By default the nightly release . json entries ( nightly and nightly - a7 ) are used . By default the pipeline builds both Agent 6 and Agent 7 . Use the -- major - versions option to specify a comma - separated string of the major Agent versions to build . - repo - branch option indicates which branch of the staging repository the packages will be deployed to ( useful only on deploy pipelines ) . If other pipelines are already running on the git ref the script will prompt the user to confirm if these previous pipelines should be cancelled . Run a pipeline on the current branch : inv pipeline . run -- here
def run(
    ctx,
    git_ref=None,
    here=False,
    use_release_entries=False,
    major_versions='6,7',
    repo_branch="nightly",
    deploy=False,
    all_builds=True,
    kitchen_tests=True,
):
    project_name = "DataDog/datadog-agent"
    gitlab = Gitlab(project_name=project_name, api_token=get_gitlab_token())
    gitlab.test_project_found()
    if not git_ref and not here:
        raise Exit("Either --here or --git-ref <git ref> must be specified.", code=1)
    if use_release_entries:
        release_version_6 = release_entry_for(6)
        release_version_7 = release_entry_for(7)
    else:
        release_version_6 = nightly_entry_for(6)
        release_version_7 = nightly_entry_for(7)
    major_versions = major_versions.split(',')
    if '6' not in major_versions:
        release_version_6 = ""
    if '7' not in major_versions:
        release_version_7 = ""
    if here:
        git_ref = ctx.run("git rev-parse --abbrev-ref HEAD", hide=True).stdout.strip()
    if deploy:
        check_deploy_pipeline(gitlab, git_ref, release_version_6, release_version_7, repo_branch)
        if not all_builds:
            print(
                color_message(
                    "WARNING: ignoring --no-all-builds option, RUN_ALL_BUILDS is automatically set to true on deploy pipelines",
                    "orange",
                )
            )
            all_builds = True
        if not kitchen_tests:
            print(
                color_message(
                    "WARNING: ignoring --no-kitchen-tests option, RUN_KITCHEN_TESTS is automatically set to true on deploy pipelines",
                    "orange",
                )
            )
            kitchen_tests = True
    pipelines = get_running_pipelines_on_same_ref(gitlab, git_ref)
    if pipelines:
        print(
            f"There are already {len(pipelines)} pipeline(s) running on the target git ref.",
            "For each of them, you'll be asked whether you want to cancel them or not.",
            "If you don't need these pipelines, please cancel them to save CI resources.",
            "They are ordered from the newest one to the oldest one.\n",
            sep='\n',
        )
        cancel_pipelines_with_confirmation(gitlab, pipelines)
    try:
        pipeline_id = trigger_agent_pipeline(
            gitlab,
            git_ref,
            release_version_6,
            release_version_7,
            repo_branch,
            deploy=deploy,
            all_builds=all_builds,
            kitchen_tests=kitchen_tests,
        )
    except FilteredOutException:
        print(color_message(f"ERROR: pipeline does not match any workflow rule. Rules:\n{workflow_rules()}", "red"))
        return
    wait_for_pipeline(gitlab, pipeline_id)
def run ( ctx , git_ref = None , here = False , use_release_entries = False , major_versions = '6,7' , repo_branch = "nightly" , deploy = False , all_builds = True , kitchen_tests = True , ) : project_name = "DataDog/datadog-agent" gitlab = Gitlab ( project_name = project_name , api_token = get_gitlab_token ( ) ) gitlab . test_project_found ( ) if not git_ref and not here : raise Exit ( "Either --here or --git-ref <git ref> must be specified." , code = 1 ) if use_release_entries : release_version_6 = release_entry_for ( 6 ) release_version_7 = release_entry_for ( 7 ) else : release_version_6 = nightly_entry_for ( 6 ) release_version_7 = nightly_entry_for ( 7 ) major_versions = major_versions . split ( ',' ) if '6' not in major_versions : release_version_6 = "" if '7' not in major_versions : release_version_7 = "" if here : git_ref = ctx . run ( "git rev-parse --abbrev-ref HEAD" , hide = True ) . stdout . strip ( ) if deploy : check_deploy_pipeline ( gitlab , git_ref , release_version_6 , release_version_7 , repo_branch ) if not all_builds : print ( color_message ( "WARNING: ignoring --no-all-builds option, RUN_ALL_BUILDS is automatically set to true on deploy pipelines" , "orange" , ) ) all_builds = True if not kitchen_tests : print ( color_message ( "WARNING: ignoring --no-kitchen-tests option, RUN_KITCHEN_TESTS is automatically set to true on deploy pipelines" , "orange" , ) ) kitchen_tests = True pipelines = get_running_pipelines_on_same_ref ( gitlab , git_ref ) if pipelines : print ( f"There are already {len(pipelines)} pipeline(s) running on the target git ref." , "For each of them, you'll be asked whether you want to cancel them or not." , "If you don't need these pipelines, please cancel them to save CI resources." , "They are ordered from the newest one to the oldest one.\n" , sep = '\n' , ) cancel_pipelines_with_confirmation ( gitlab , pipelines ) try : pipeline_id = trigger_agent_pipeline ( gitlab , git_ref , release_version_6 , release_version_7 , repo_branch , deploy = deploy , all_builds = all_builds , kitchen_tests = kitchen_tests , ) except FilteredOutException : print ( color_message ( f"ERROR: pipeline does not match any workflow rule. Rules:\n{workflow_rules()}" , "red" ) ) return wait_for_pipeline ( gitlab , pipeline_id )
Run a pipeline on the given git ref (--git-ref <git ref>), or on the current branch if --here is given.
Run a pipeline on the given git ref ( -- git - ref <git ref > ) or on the current branch if -- here is given .
"""
    Run a pipeline on the given git ref (--git-ref <git ref>), or on the current branch if --here is given.
    By default, this pipeline will run all builds & tests, including all kitchen tests, but is not a deploy pipeline.
    Use --deploy to make this pipeline a deploy pipeline, which will upload artifacts to the staging repositories.
    Use --no-all-builds to not run builds for all architectures (only a subset of jobs will run. No effect on pipelines on the default branch).
    Use --no-kitchen-tests to not run all kitchen tests on the pipeline.

    By default, the nightly release.json entries (nightly and nightly-a7) are used.
    Use the --use-release-entries option to use the release-a6 and release-a7 release.json entries instead.

    By default, the pipeline builds both Agent 6 and Agent 7.
    Use the --major-versions option to specify a comma-separated string of the major Agent versions to build
    (eg. '6' to build Agent 6 only, '6,7' to build both Agent 6 and Agent 7).

    The --repo-branch option indicates which branch of the staging repository the packages will be deployed to (useful only on deploy pipelines).

    If other pipelines are already running on the git ref, the script will prompt the user to confirm if these previous
    pipelines should be cancelled.

    Examples
    Run a pipeline on my-branch:
      inv pipeline.run --git-ref my-branch

    Run a pipeline on the current branch:
      inv pipeline.run --here

    Run a pipeline without kitchen tests on the current branch:
      inv pipeline.run --here --no-kitchen-tests

    Run a deploy pipeline on the 7.32.0 tag, uploading the artifacts to the stable branch of the staging repositories:
      inv pipeline.run --deploy --use-release-entries --major-versions "6,7" --git-ref "7.32.0" --repo-branch "stable"
    """ # Check the validity of the deploy pipeline # Force all builds and kitchen tests to be run
ctx
git_ref
here
use_release_entries
major_versions
repo_branch
deploy
all_builds
kitchen_tests