Skip to content
Back to skills

Cicd Jenkins

ASecurity

Jenkins — declarative Jenkinsfile for build, test, and deploy.

  • 6 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
ai-agentsnodedockergit

Security analysis

A100/100

Scanned September 5, 2026

npx -y skills add Dev-Toolbelt/dev-team-agents --skill cicd-jenkins --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cicd Jenkins?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cicd Jenkins
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/dev-toolbelt-cicd-jenkins/badge)](https://www.skillsdirectory.com/skills/dev-toolbelt-cicd-jenkins)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cicd-jenkins
description: Jenkins — declarative Jenkinsfile for build, test, and deploy.
---

# Jenkins Pipelines

## Declarative Jenkinsfile (preferred)

```groovy
// Jenkinsfile
pipeline {
    agent {
        docker {
            image 'node:20-alpine'
            args '-v /var/run/docker.sock:/var/run/docker.sock'
        }
    }

    environment {
        REGISTRY = credentials('docker-registry-url')
        DEPLOY_KEY = credentials('deploy-ssh-key')
    }

    options {
        timeout(time: 30, unit: 'MINUTES')
        disableConcurrentBuilds()
        buildDiscarder(logRotator(numToKeepStr: '10'))
    }

    stages {
        stage('Install') {
            steps {
                sh 'npm ci'
            }
        }

        stage('Lint') {
            steps {
                sh 'npm run lint'
            }
        }

        stage('Test') {
            steps {
                sh 'npm test'
            }
            post {
                always {
                    junit 'test-results/*.xml'
                }
            }
        }

        stage('Build Image') {
            when {
                branch 'main'
            }
            steps {
                sh "docker build -t ${REGISTRY}/myapp:${GIT_COMMIT} ."
                sh "docker push ${REGISTRY}/myapp:${GIT_COMMIT}"
            }
        }

        stage('Deploy') {
            when {
                branch 'main'
            }
            input {
                message 'Deploy to production?'
                ok 'Deploy'
            }
            steps {
                sshagent(['deploy-ssh-key']) {
                    sh """
                        ssh -o StrictHostKeyChecking=no deploy@${DEPLOY_HOST} '
                            cd /opt/myapp &&
                            IMAGE_TAG=${GIT_COMMIT} docker compose pull app &&
                            IMAGE_TAG=${GIT_COMMIT} docker compose up -d &&
                            docker image prune -f
                        '
                    """
                }
            }
        }
    }

    post {
        failure {
            mail to: 'team@example.com',
                 subject: "Pipeline failed: ${env.JOB_NAME}",
                 body: "Build ${env.BUILD_URL} failed."
        }
    }
}
```

## Credentials Management

- Store all secrets in **Jenkins Credentials** (not Jenkinsfile)
- Use `credentials()` binding or `withCredentials` block
- Types: Username/Password, SSH Key, Secret Text, Secret File
- Never echo credentials — use `set +x` if you must debug

```groovy
withCredentials([usernamePassword(
    credentialsId: 'docker-registry',
    usernameVariable: 'DOCKER_USER',
    passwordVariable: 'DOCKER_PASS'
)]) {
    sh 'docker login -u $DOCKER_USER -p $DOCKER_PASS'
}
```

## Shared Libraries

For reusable pipeline logic across repositories:

```groovy
// Jenkinsfile
@Library('my-shared-library') _

deployApp(environment: 'production', image: 'myapp')
```

## Best Practices

- Use **declarative** syntax over scripted — more readable and constrained
- Use `agent { docker {} }` to run in containers — no environment pollution
- `disableConcurrentBuilds()` prevents race conditions on shared resources
- `buildDiscarder` prevents disk exhaustion from keeping old builds
- Use `input` for manual approval gates before production deploys
- Add `timeout` to prevent stuck builds from blocking the executor
- Use `post { always {} }` for test report publishing — runs even on failure
- Configure Blue Ocean plugin for better UI visualization

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.