A GitLab CI/CD job template that posts an Open workspace badge comment on new GitLab issues, powered by Worktree.
When a new issue is created, a comment like this is automatically posted:
A workspace is ready for this issue.
In your GitLab project go to Settings → CI/CD → Variables and add:
| Key | Value | Flags |
|---|---|---|
WORKTREE_GITLAB_TOKEN |
A personal access token with api scope |
Masked |
Go to Settings → CI/CD → Pipeline triggers and create a new trigger token. Copy the token — you'll need it for the webhook bridge.
GitLab webhooks send JSON payloads, but the pipeline trigger API accepts form parameters. Deploy this Cloudflare Worker to bridge them:
export default {
async fetch(request, env) {
if (request.method !== "POST") return new Response("Method Not Allowed", { status: 405 });
const payload = await request.json();
const event = payload.object_kind;
if (event !== "issue" || payload.object_attributes?.action !== "open") {
return new Response("ignored", { status: 200 });
}
const iid = payload.object_attributes.iid;
const projectId = payload.project.id;
const body = new URLSearchParams({
token: env.TRIGGER_TOKEN,
ref: env.REF || "main",
"variables[ISSUE_IID]": String(iid),
});
const resp = await fetch(
`https://gitlab.com/api/v4/projects/${projectId}/trigger/pipeline`,
{ method: "POST", body }
);
const text = await resp.text();
return new Response(text, { status: resp.status });
},
};Set the following Worker secrets / environment variables:
TRIGGER_TOKEN— the pipeline trigger token from step 2REF— the branch to run the pipeline on (default:main)
In Settings → Webhooks, add a webhook pointing to your Worker URL and enable Issues events.
Add this to your .gitlab-ci.yml:
include:
- remote: 'https://raw.githubusercontent.com/worktree-io/gitlab-comment-action/v1/templates/comment.yml'That's it. When a new issue is opened, the webhook fires the Worker, which triggers a pipeline with ISSUE_IID set — the worktree-comment job picks it up and posts the comment.
- The job runs in the
.prestage and only whenCI_PIPELINE_SOURCE == "trigger"andISSUE_IIDis set, so it never interferes with normal pipelines. GIT_STRATEGY: nonemeans no repository checkout is needed — the job finishes in seconds.- The comment body is built with
printfand safely JSON-encoded withjqbefore being sent to the GitLab Notes API.
MIT