{"id":21893223,"url":"https://github.com/jase88/nx-gitlab-ci-filter-affected","last_synced_at":"2026-02-25T12:12:06.978Z","repository":{"id":265141444,"uuid":"891626097","full_name":"jase88/nx-gitlab-ci-filter-affected","owner":"jase88","description":"nx-gitlab-ci-filter-affected is a CLI tool for nx monorepo users who use Gitlab and want to filter their pipeline jobs dynamically based on nx affected.","archived":false,"fork":false,"pushed_at":"2025-03-31T09:52:36.000Z","size":361,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T10:37:43.588Z","etag":null,"topics":["gitlab","gitlab-ci","nx","nx-affected"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jase88.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-20T17:00:40.000Z","updated_at":"2025-03-31T09:52:33.000Z","dependencies_parsed_at":"2025-02-03T08:27:18.281Z","dependency_job_id":"a65db6ad-affd-4ca1-a39b-4b507855586a","html_url":"https://github.com/jase88/nx-gitlab-ci-filter-affected","commit_stats":null,"previous_names":["jase88/nx-gitlab-ci-filter-affected"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jase88%2Fnx-gitlab-ci-filter-affected","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jase88%2Fnx-gitlab-ci-filter-affected/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jase88%2Fnx-gitlab-ci-filter-affected/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jase88%2Fnx-gitlab-ci-filter-affected/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jase88","download_url":"https://codeload.github.com/jase88/nx-gitlab-ci-filter-affected/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249095228,"owners_count":21211888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gitlab","gitlab-ci","nx","nx-affected"],"created_at":"2024-11-28T13:12:54.339Z","updated_at":"2026-02-25T12:12:06.973Z","avatar_url":"https://github.com/jase88.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nx-gitlab-ci-filter-affected\n`nx-gitlab-ci-filter-affected` is a CLI tool for `nx` monorepo users who use `Gitlab` and want to filter their pipeline jobs dynamically based on nx affected.\n\nAn existing Gitlab pipeline is expected as input. In this pipeline, variables can be used to define whether a job is to be filtered using an nx target or one or more nx projects.\n\n`nx-gitlab-ci-filter-affected` writes to the job variables whether the job is affected or not and which projects are affected. So that this information can be reused within the jobs.\n\n## Why filtering Gitlab CI jobs by nx affected?\n\nSince Gitlab does not yet offer the option of reacting to variables generated at runtime, there are only limited options for not executing jobs if they are not `nx affected`.\n\nOne possibility is to write a dynamic pipeline that can then be started by Gitlab as a child pipeline. This is exactly the approach taken with this CLI tool.\n\n## Usage\n\n`npx nx-gitlab-ci-filter-affected --input pipeline.yml --output affected.yml`\n\nThe CLI requires an input and output file path relative to the current working directory.\n\nAlternatively you can set the environment variables `NX_GL_PIPELINE_INPUT` and `NX_GL_PIPELINE_OUTPUT`.\n\n### Example\n\n```yaml\ncalculate-affected:\n  image: node:23.2.0-alpine3.20\n  variables:\n    NX_GL_PIPELINE_INPUT: 'gitlab-ci.all.yml'\n    NX_GL_PIPELINE_OUTPUT: 'affected.yml'\n  before_script:\n    - |\n      NX_HEAD=$CI_COMMIT_SHA\n      NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}\n      if [ \"$NX_BASE\" = \"0000000000000000000000000000000000000000\" ]; then NX_BASE=\"origin/$CI_DEFAULT_BRANCH\"; fi;\n    - git fetch origin $CI_DEFAULT_BRANCH:$CI_DEFAULT_BRANCH\n  script:\n    - npx nx-gitlab-ci-filter-affected\n  artifacts:\n    paths:\n      - affected.yml\n\nrun-affected:\n  needs:\n    - job: calculate-affected\n      artifacts: true\n  trigger:\n    include:\n      - artifact: affected.yml\n        job: calculate-affected\n```\n\n## Configuration of the pipeline\n\n### Target\nEvery job has to define a nx target that is used to filter the affected projects.\nThis is done with the variable `NX_GL_TARGET`.\n\n### Example\n```yaml\nlint:\n  variables:\n    NX_GL_TARGET: 'lint'\n  script:\n    # ...\n```\n\nThis job afterward receives a variable called `NX_GL_IS_AFFECTED`, so that a rule like\n```yaml\nlint:\n  rules:\n    - if: '$NX_GL_IS_AFFECTED == \"true\"'\n ```\ncould filter the job if not affected.\n\n\n### Projects\nAdditionally, to the target there can be a list of projects that are used to filter the affected projects.\nThis is done with the variable `NX_GL_PROJECTS`. It can be comma separated list of projects or a project pattern. \n```yaml\nbuild-app1:\n  variables:\n    NX_GL_TARGET: 'build'\n    NX_GL_PROJECTS: 'app1'\n  script:\n    - nx build app1\n```\n\nThis job will have set `NX_GL_IS_AFFECTED` to `true` in the pipeline if the target `build` for the project `app1` is affected.\n\n### List of affected projects\n\nAdditionally to the filtering of the jobs, the affected projects are passed to the job as a variable.\n#### Input\n```yaml\nlint:\n  variables:\n    NX_GL_TARGET: 'lint'\n  script:\n    - echo \"Building $NX_GL_AFFECTED_PROJECTS\"\n```\n\n#### Output\n```yaml\nlint:\n  variables:\n    NX_GL_TARGET: 'lint'\n    NX_GL_AFFECTED_PROJECTS: 'project1,project2'\n    NX_GL_IS_AFFECTED: 'true'\n  script:\n    - echo \"Building $NX_GL_AFFECTED_PROJECTS\"\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjase88%2Fnx-gitlab-ci-filter-affected","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjase88%2Fnx-gitlab-ci-filter-affected","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjase88%2Fnx-gitlab-ci-filter-affected/lists"}