Jenkins Declarative Pipeline Per Repo logo

Jenkins Declarative Pipeline Per Repo

Community
selvarajmurugesan90
jenkins-declarative-pipeline-per-repo

Authors and troubleshoots a per-repo Jenkinsfile using Jenkins Declarative Pipeline syntax — agent, stages, steps, post, environment, and when blocks — for a single repository's own build/test/deploy flow. Use when the user asks to "write a Jenkinsfile," "add a declarative pipeline to this repo," "fix a failing Jenkins stage," "add a post-build notification to Jenkins," or "set up per-repo CI in Jenkins" without a shared organization-wide library.

Add to TypingMind

Overview

Publisherselvarajmurugesan90
Repositoryops-engineering-skills
Skill namejenkins-declarative-pipeline-per-repo
Stars
44
Forks
18
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by selvarajmurugesan90 on GitHub. Read the source before you install it.

Installation

Install the Jenkins Declarative Pipeline Per Repo AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/selvarajmurugesan90/ops-engineering-skills/tree/main/plugins/cicd-tooling/skills/jenkins-declarative-pipeline-per-repo
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/selvarajmurugesan90/ops-engineering-skills.git /tmp/ops-engineering-skills
mkdir -p .claude/skills
cp -r /tmp/ops-engineering-skills/plugins/cicd-tooling/skills/jenkins-declarative-pipeline-per-repo .claude/skills/jenkins-declarative-pipeline-per-repo
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Jenkins Declarative Pipeline Per Repo in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Jenkins Declarative Pipeline Per Repo on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Jenkins Declarative Pipeline Per Repo is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Jenkins Declarative Pipeline Per Repo

Purpose

A per-repo Jenkinsfile puts pipeline-as-code directly in the repository it builds: it's reviewed in the same pull request as the code change, versioned alongside it, and doesn't require a Jenkins administrator to touch a separate job configuration. This skill covers Jenkins Declarative Pipeline syntax specifically — the agent/stages/steps/post block structure, environment and when conditionals, and the concrete constructs (not generic CI concepts, which are covered in ci-cd-pipeline-design) needed to write a correct, maintainable Jenkinsfile that lives in a single repo. It also covers the specific trade-off of the per-repo model versus centralizing logic in a shared library, so a team can make an informed choice rather than defaulting to copy-paste.

When to use

  • A repository has no Jenkinsfile yet and needs one for build/test/package.
  • An existing per-repo Jenkinsfile is failing at a specific stage and needs debugging (syntax error, wrong agent label, a when condition that never matches).
  • Adding a post block for Slack/email notification on failure, or a always cleanup step (e.g. deleteDir()), to an existing pipeline.
  • Deciding whether pipeline logic that's growing complex in one Jenkinsfile should stay per-repo or be extracted into a shared library — see jenkins-centralized-shared-library for that migration.
  • Reviewing a Jenkinsfile PR and needing to know whether sh, script, or a plugin step is idiomatic for a given task.

Prerequisites & environment

  • A Jenkins controller (2.401+ LTS recommended for current Declarative Pipeline features) with the Pipeline plugin suite installed (workflow-aggregator), which ships Declarative Pipeline support.
  • The repo is registered as a Multibranch Pipeline or Pipeline job with "Pipeline script from SCM" pointing at Jenkinsfile in the repo root (or a path configured in the job) — the Jenkinsfile is not useful without a job/multibranch config that reads it from SCM.
  • Build agents (nodes) with the required labels available — e.g. a docker or linux-x64 label matching what the Jenkinsfile's agent block requests. Confirm labels via Manage Jenkins → Nodes.
  • Credentials (SSH keys, registry tokens, cloud creds) already created in Manage Jenkins → Credentials with known IDs — a Jenkinsfile only references a credential ID (${JENKINS_CRED_ID}), it never stores the secret value itself.
  • For Docker-based agents: the controller/agent has Docker available and the Docker Pipeline plugin installed if using agent { docker { ... } }.

Step-by-step guidance

  1. Start from the top-level pipeline block — Declarative Pipeline requires exactly one pipeline { } block; you cannot mix bare Scripted Pipeline steps at the top level.

    groovy
    pipeline {
        agent any
        options {
            timestamps()
            timeout(time: 30, unit: 'MINUTES')
            disableConcurrentBuilds()
        }
        environment {
            IMAGE_NAME = 'registry.example.com/myapp'
        }
        stages {
            stage('Checkout') {
                steps {
                    checkout scm
                }
            }
        }
    }
  2. Pin agent precisely, not just agent any. Use a label for a specific node pool, or a docker agent for a reproducible toolchain pinned by image tag:

    groovy
    agent {
        docker {
            image 'node:20.11-bullseye'
            args '-v $HOME/.npm:/home/node/.npm'
        }
    }

    agent any is fine for a small team with a homogeneous fleet; pin a label or Docker image once tooling versions must be reproducible or multiple agent types exist.

  3. Model real stages, not one giant script block. Each logical phase (checkout, build, test, package, deploy) is its own stage, so the Jenkins UI/API shows per-stage pass/fail and timing:

    groovy
    stages {
        stage('Build') {
            steps { sh 'npm ci && npm run build' }
        }
        stage('Test') {
            steps { sh 'npm test -- --reporter=junit --output=reports/junit.xml' }
            post {
                always {
                    junit 'reports/junit.xml'
                }
            }
        }
        stage('Package') {
            steps {
                sh 'docker build -t ${IMAGE_NAME}:${GIT_COMMIT} .'
            }
        }
        stage('Deploy to staging') {
            when {
                branch 'main'
            }
            steps {
                withCredentials([usernamePassword(credentialsId: '${JENKINS_CRED_ID}',
                                                   usernameVariable: 'REG_USER',
                                                   passwordVariable: 'REG_PASS')]) {
                    sh '''
                      echo "$REG_PASS" | docker login registry.example.com -u "$REG_USER" --password-stdin
                      docker push ${IMAGE_NAME}:${GIT_COMMIT}
                    '''
                }
            }
        }
    }
  4. Use when for conditional stages instead of shell-level if guards so skipped stages show clearly as "skipped" in the UI rather than as a confusing green no-op:

    groovy
    when {
        allOf {
            branch 'main'
            not { changeRequest() }
        }
    }
  5. Drop into script { } only for real Groovy logic (loops, conditionals on computed values) that the declarative DSL can't express directly — keep these blocks small; anything non-trivial belongs in a shared library function, see jenkins-centralized-shared-library.

    groovy
    steps {
        script {
            def version = sh(script: 'git describe --tags --always', returnStdout: true).trim()
            env.BUILD_VERSION = version
        }
    }
  6. Add post for outcome-based actions — notification, cleanup, artifact archiving — always at the pipeline level (and per-stage where needed):

    groovy
    post {
        success {
            slackSend(channel: '#builds', color: 'good', message: "Build ${env.BUILD_NUMBER} succeeded")
        }
        failure {
            slackSend(channel: '#builds', color: 'danger', message: "Build ${env.BUILD_NUMBER} failed: ${env.BUILD_URL}")
        }
        always {
            archiveArtifacts artifacts: 'dist/**', allowEmptyArchive: true
            cleanWs()
        }
    }
  7. Validate syntax before pushing using the Jenkins CLI or the Jenkinsfile linter endpoint:

    bash
    curl -s -X POST -u ${JENKINS_USER}:${JENKINS_API_TOKEN} \
      -F "jenkinsfile=<Jenkinsfile" \
      https://jenkins.example.com/pipeline-model-converter/validate

    Catching a WorkflowScript: 12: Expected one of ... error here is far faster than waiting for a real build to fail at parse time.

Best practices

  • Keep the Jenkinsfile declarative end-to-end; reach for script {} only for logic the DSL genuinely can't express, and keep those blocks under ~10 lines — anything bigger is a sign the logic belongs in a shared library function instead of inline Groovy (see jenkins-groovy-scripting-best-practices).
  • Set options { timeout(...) } and disableConcurrentBuilds() (or options { skipDefaultCheckout() } where appropriate) explicitly — a Jenkinsfile with no timeout can hang a stuck agent indefinitely, tying up an executor.
  • Reference credentials only by ID (withCredentials, credentialsId:), never inline — Jenkins masks values referenced this way in console output automatically; a value assigned to a plain env var from a credential is not masked.
  • Use junit/archiveArtifacts/recordIssues (Warnings Next Generation plugin) to surface structured results in the Jenkins UI rather than only a pass/fail exit code — this mirrors the "fail fast and make failures actionable" guidance in ci-cd-pipeline-design.
  • Decide early whether logic is genuinely repo-specific (belongs inline) or organization-wide (belongs in a shared library) — a Jenkinsfile that has grown past ~150 lines of duplicated logic across many repos is the signal to migrate, see jenkins-centralized-shared-library.
  • Version-pin plugin-provided steps where the plugin has known breaking changes between major versions (check the plugin's changelog before a Jenkins upgrade), since a per-repo Jenkinsfile has no central place to absorb a plugin API change across many repos.

Common pitfalls

  • Symptom: Pipeline fails immediately with WorkflowScript: 3: Expected one of "pipeline", ... @ line 3, column 1. Fix: Declarative Pipeline requires the single top-level pipeline {} block with no bare Groovy statements or Scripted-style node {} outside it; move any Scripted-style code inside a script {} block within a steps block.

  • Symptom: deploy stage runs on every branch, including feature branches, even though it's "supposed to" only run on main. Fix: Add an explicit when { branch 'main' } (or when { allOf { branch 'main'; not { changeRequest() } } }) to the stage — without it, a Multibranch Pipeline job runs every stage on every discovered branch.

  • Symptom: A credential value shows up in plaintext in the build console log. Fix: Never assign a credential to a plain environment variable via environment { TOKEN = credentials('id') } followed by manual echo, and never sh "curl -H Authorization: ${TOKEN}" without quoting through withCredentials's masked bindings — use withCredentials([...]) and keep the secret variable inside its scope; Jenkins only masks values it knows are secret-bound in that block.

  • Symptom: Build hangs for hours consuming an executor after an agent goes unresponsive mid-sh step. Fix: Add options { timeout(time: 30, unit: 'MINUTES') } at the pipeline or stage level so a stuck step is killed and the executor freed instead of blocking indefinitely.

  • Symptom: Two builds of the same branch run concurrently and race on a shared resource (e.g. both push to the same tag). Fix: Add options { disableConcurrentBuilds() }, or narrow it with disableConcurrentBuilds(abortPrevious: true) (Jenkins 2.263+) so a new build cancels the superseded one rather than running in parallel.

Worked example

Scenario: A single Node.js service repo needs its own Jenkinsfile: lint/test on every branch and PR, Docker build + push to a registry only on main, with Slack notification on failure.

Jenkinsfile (repo root):

groovy
pipeline {
    agent {
        docker { image 'node:20.11-bullseye' }
    }
    options {
        timestamps()
        timeout(time: 20, unit: 'MINUTES')
        disableConcurrentBuilds(abortPrevious: true)
    }
    environment {
        IMAGE_NAME = 'registry.example.com/myapp'
    }
    stages {
        stage('Install & Lint') {
            steps {
                sh 'npm ci'
                sh 'npm run lint'
            }
        }
        stage('Test') {
            steps {
                sh 'npm test -- --reporter=junit --outputFile=reports/junit.xml'
            }
            post {
                always { junit 'reports/junit.xml' }
            }
        }
        stage('Build & Push image') {
            when { branch 'main' }
            steps {
                sh 'docker build -t ${IMAGE_NAME}:${GIT_COMMIT} .'
                withCredentials([usernamePassword(credentialsId: '${JENKINS_CRED_ID}',
                                                   usernameVariable: 'REG_USER',
                                                   passwordVariable: 'REG_PASS')]) {
                    sh '''
                      echo "$REG_PASS" | docker login registry.example.com -u "$REG_USER" --password-stdin
                      docker push ${IMAGE_NAME}:${GIT_COMMIT}
                    '''
                }
            }
        }
    }
    post {
        failure {
            slackSend(channel: '#builds', color: 'danger',
                      message: "FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER} (${env.BUILD_URL})")
        }
        always {
            cleanWs()
        }
    }
}

This runs identically whether triggered by a PR or a main push, only gating the image push stage with when { branch 'main' }, and keeps the registry credential scoped to the one withCredentials block that needs it.

Cross-references

Frequently asked questions

What does the Jenkins Declarative Pipeline Per Repo AI skill do?

Authors and troubleshoots a per-repo Jenkinsfile using Jenkins Declarative Pipeline syntax — agent, stages, steps, post, environment, and when blocks — for a single repository's own build/test/deploy flow. Use when the user asks to "write a Jenkinsfile," "add a declarative pipeline to this repo," "fix a failing Jenkins stage," "add a post-build notification to Jenkins," or "set up per-repo CI in Jenkins" without a shared organization-wide library.

Why use Jenkins Declarative Pipeline Per Repo on TypingMind?

Because you install it once and use it with any model. Jenkins Declarative Pipeline Per Repo is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Jenkins Declarative Pipeline Per Repo in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/selvarajmurugesan90/ops-engineering-skills/tree/main/plugins/cicd-tooling/skills/jenkins-declarative-pipeline-per-repo. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Jenkins Declarative Pipeline Per Repo?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Jenkins Declarative Pipeline Per Repo?

As many as you like. As long as a model supports skills, you can use Jenkins Declarative Pipeline Per Repo with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Jenkins Declarative Pipeline Per Repo AI skill free?

Yes. It is published on GitHub by selvarajmurugesan90 under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇