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.

    • GITLAB_TOKEN_FOR_JUNIE with a personal or group Gitlab access token. Make sure that the token has at least Maintainer role and the api checkbox selected for Selected scope. Select init from the Environments dropdown to restrict the variable's exposure to Junie initialization jobs.

  3. 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 lost 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
14 March 2026