Junie Help

Junie GitLab CI/CD

Run AI tasks from GitLab issues or MRs with Junie GitLab CI/CD.

How it works

Junie GitLab CI/CD integrates Junie into your GitLab CI/CD pipelines.

When you tag #junie in a comment to a GitLab issue or merge request, the agent is invoked to run the task. Junie runs a CI pipeline to execute the task, creates a new Merge Request with the changes, and posts a comment with a link to the created MR.

Junie gitlab issue comment

Why use Junie GitLab CI/CD?

  • Delegate tasks to Junie: Junie creates merge requests with code changes from issue comments.

  • Have Junie review MRs: Tag and instruct #junie in a comment to an existing merge request to have the agent review and fix the changes before merging.

  • Fix issues in projects without opening the IDE: When running the task, the agent is aware of your entire project structure, agent guidelines, and existing code patterns the same way as it would when working directly in the IDE.

  • Iterate on tasks with follow-up instructions: The MR submitted by Junie needs another iteration? Tag #junie in a comment to it and provide follow-up instructions.

  • Work on multiple tasks at a time: Junie GitLab CI/CD can work on multiple tasks simultaneously, excluding parallel runs on the same MR branch.

Setup

The setup process requires creation of a separate container project for Junie's CI/CD pipelines (one per GitLab instance). This allows you to run Junie without tweaking the CI/CD pipelines in your existing projects.

Step 1: Set up a project for Junie

  1. Create a new empty GitLab project.

  2. Add the following environment variables in the project's SettingsCI/CDVariables:

  • JUNIE_API_KEY with your API token for Junie. To generate the token, go to junie.jetbrains.com/cli.

    Alternatively, instead of JUNIE_API_KEY, you can use your own API key from a third-party LLM provider (BYOK). Add one of the following variables: JUNIE_OPENAI_API_KEY, JUNIE_ANTHROPIC_API_KEY, JUNIE_GROK_API_KEY, JUNIE_OPENROUTER_API_KEY, or JUNIE_GOOGLE_API_KEY.

  • GITLAB_TOKEN_FOR_JUNIE with a GitLab access token. Choose the setup that matches your token type and GitLab version:

    • Personal access tokens on any GitLab version, or group access tokens on GitLab versions earlier than 19: use a personal or group access token, respectively, and store it in GITLAB_TOKEN_FOR_JUNIE. The user or bot associated with the token needs at least the Maintainer role in each project where Junie will be invoked. In the project that runs Junie's CI/CD pipelines, Maintainer is sufficient for basic functionality, but Owner is required to automatically delete completed pipelines.

      If you choose a fine-grained personal access token, make sure the user who owns the token has the following permissions for initialization and cleanup, and that the token grants access to them:

      • In each project where Junie will be invoked:

        • Read and create webhooks.

        • Create project access tokens.

      • In the project that runs Junie's CI/CD pipelines:

        • Read, create, and delete pipeline trigger tokens. Initialization deletes existing Junie trigger tokens before creating a replacement if the project's Junie webhook is missing.

        • Delete pipelines, if you use automatic pipeline cleanup. The Owner role alone does not grant this permission to a fine-grained token.

    • Service accounts on GitLab 19 and later: use a service account instead of a group access token:

      1. Create a new service account in your GitLab group.

      2. Create an access token for the service account and store it in GITLAB_TOKEN_FOR_JUNIE.

      3. Add the service account to the project that runs Junie's CI/CD pipelines with the Owner role. The Maintainer role is sufficient for basic functionality, but Owner is required to automatically delete completed pipelines.

      4. Add the service account to each project where Junie will be invoked with the Maintainer role.

    For tokens other than fine-grained personal access tokens, select api under Selected scope when creating the token. Select init from the variable's Environments dropdown to make it available to the junie-init and junie-cleanup jobs, which use this environment.

  1. Add a .gitlab-ci.yml file with the following contents to the project:

spec: inputs: project_token: type: string default: "" --- variables: PROJECTS_TO_INIT: value: "" description: "Comma-separated list of project IDs to initialize" INPUT_TOKEN: value: "$[[ inputs.project_token ]]" description: "Project's access token" stages: - junie - cleanup .trigger-conditions: - &if-junie-note '$CI_PIPELINE_SOURCE == "trigger" && $EVENT_KIND == "note" && ($COMMENT_TEXT =~ /#junie(\s|$)/i || $COMMENT_TEXT =~ /@project_[0-9]+_bot/i)' - &if-mr-open '$CI_PIPELINE_SOURCE == "trigger" && $EVENT_KIND == "merge_request" && $MR_EVENT_ACTION == "open"' junie-init: stage: junie environment: init image: registry.jetbrains.team/p/matterhorn/public/junie-gitlab-wrapper:latest script: - node /app/dist/cli.js init --verbose $PROJECTS_TO_INIT when: manual rules: - if: $CI_PIPELINE_SOURCE == "web" when: manual - when: never junie-run: stage: junie image: registry.jetbrains.team/p/matterhorn/public/junie-gitlab-wrapper:latest script: - rm -rf * .* # clean up the workdir before checking out a remote project - node /app/dist/cli.js run --verbose after_script: - mkdir -p junie-artifacts/working-directory - mkdir -p junie-artifacts/logs - mkdir -p junie-artifacts/sessions - cp -R /junieCache/. ./junie-artifacts/working-directory/ 2>/dev/null || true - cp -R ~/.junie/logs/. ./junie-artifacts/logs/ 2>/dev/null || true - cp -R ~/.junie/sessions/. ./junie-artifacts/sessions/ 2>/dev/null || true rules: - if: *if-junie-note when: always - if: *if-mr-open when: always variables: JUNIE_CUSTOM_PROMPT: "code-review" - when: never variables: GITLAB_TOKEN_FOR_JUNIE: "$INPUT_TOKEN" # Pattern for matching Junie bot mentions inside the wrapper code # NOTE: Keep this in sync with JUNIE_MENTION_TRIGGER and the regex in rules above JUNIE_MODEL: "sonnet" # Use Claude instead of Gemini for MCP compatibility USE_MCP: true artifacts: reports: dotenv: junie-artifacts/working-directory/wrapper-outputs.env paths: - junie-artifacts/working-directory - junie-artifacts/logs - junie-artifacts/sessions expire_in: 1 week when: always # Deletes a pipeline if it was an "IDLE" run junie-cleanup: stage: cleanup environment: init image: registry.jetbrains.team/p/matterhorn/public/junie-gitlab-wrapper:latest rules: - if: '$CI_PIPELINE_SOURCE == "trigger" && $EVENT_KIND == "note" && (($COMMENT_TEXT =~ /#junie(\s|$)/i && $DELETE_PIPELINE == "true") || $COMMENT_TEXT !~ /#junie(\s|$)/i)' when: on_success - if: '$CI_PIPELINE_SOURCE == "trigger" && $EVENT_KIND == "merge_request" && $MR_EVENT_ACTION != "open"' when: on_success - when: never script: - node /app/dist/cli.js cleanup dependencies: - junie-run

Step 2: Initialize Junie in your project

  1. In Junie's project, go to BuildPipelines and click New pipeline.

  2. On the Run new pipeline page that opens, fill in the Variable value for the PROJECTS_TO_INIT Variable key with a comma-separated list of IDs for the projects where Junie needs to be initialized. For a project's ID, go to its SettingsGeneral page.

    New gitlab pipeline
  3. Click the New pipeline button to open the new pipeline's page and run it.

    New gitlab pipeline run
  4. Once the pipeline run is finished, make sure that the target projects have a webhook for triggering pipelines in Junie's project (SettingsWebhooks) and an access token allowing Junie to access the project's repository, MRs, or issues (SettingsAccess tokens).

    Gitlab webhooks list
    Gitlab access tokens list

Use Junie GitLab CI/CD

Basic usage

Type #junie or tag the Junie by JetBrains bot in an issue comment, followed by the description of what needs to be done.

Gitlab junie comment
Gitlab junie mention

Code reviews

Junie will perform a code review with a pre-defined prompt for any opened merge request automatically.

Gitlab auto review
  • To customize the prompt for automatically triggered reviews, adjust the JUNIE_CUSTOM_PROMPT variable in the .gitlab-ci.yml configuration file.

  • To disable automated code reviews, uncheck the Merge request events checkbox in the Junie webhook's settings.

  • To trigger a code review in an existing merge request on demand, leave a comment tagging Junie along with the code-review keyword.

    Gitlab junie mr review
10 September 2026