$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill jenkinsCreate and manage Jenkins CI/CD pipelines, configure agents, manage plugins, and automate builds. Use when working with Jenkins servers, creating Jenkinsfiles, or setting up build automation for enterprise environments.
| 1 | # Jenkins |
| 2 | |
| 3 | Build, test, and deploy applications using Jenkins, the leading open-source automation server. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Setting up Jenkins pipelines (declarative or scripted) |
| 9 | - Configuring Jenkins agents and executors |
| 10 | - Managing Jenkins plugins and security |
| 11 | - Creating shared libraries for pipeline reuse |
| 12 | - Integrating Jenkins with external tools |
| 13 | |
| 14 | ## Prerequisites |
| 15 | |
| 16 | - Jenkins server (2.x or later) |
| 17 | - Admin access to Jenkins |
| 18 | - Java 11+ on Jenkins server |
| 19 | - Basic Groovy understanding for pipelines |
| 20 | |
| 21 | ## Declarative Pipeline |
| 22 | |
| 23 | Create `Jenkinsfile` in repository root: |
| 24 | |
| 25 | ```groovy |
| 26 | pipeline { |
| 27 | agent any |
| 28 | |
| 29 | environment { |
| 30 | DOCKER_REGISTRY = 'registry.example.com' |
| 31 | APP_NAME = 'myapp' |
| 32 | } |
| 33 | |
| 34 | stages { |
| 35 | stage('Build') { |
| 36 | steps { |
| 37 | sh 'npm ci' |
| 38 | sh 'npm run build' |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | stage('Test') { |
| 43 | steps { |
| 44 | sh 'npm test' |
| 45 | } |
| 46 | post { |
| 47 | always { |
| 48 | junit 'test-results/*.xml' |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | stage('Deploy') { |
| 54 | when { |
| 55 | branch 'main' |
| 56 | } |
| 57 | steps { |
| 58 | sh './deploy.sh' |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | post { |
| 64 | failure { |
| 65 | mail to: 'team@example.com', |
| 66 | subject: "Pipeline Failed: ${env.JOB_NAME}", |
| 67 | body: "Check console output at ${env.BUILD_URL}" |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | ``` |
| 72 | |
| 73 | ## Agent Configuration |
| 74 | |
| 75 | ### Docker Agent |
| 76 | |
| 77 | ```groovy |
| 78 | pipeline { |
| 79 | agent { |
| 80 | docker { |
| 81 | image 'node:20' |
| 82 | args '-v /tmp:/tmp' |
| 83 | } |
| 84 | } |
| 85 | stages { |
| 86 | stage('Build') { |
| 87 | steps { |
| 88 | sh 'npm ci && npm run build' |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | ``` |
| 94 | |
| 95 | ### Kubernetes Agent |
| 96 | |
| 97 | ```groovy |
| 98 | pipeline { |
| 99 | agent { |
| 100 | kubernetes { |
| 101 | yaml ''' |
| 102 | apiVersion: v1 |
| 103 | kind: Pod |
| 104 | spec: |
| 105 | containers: |
| 106 | - name: node |
| 107 | image: node:20 |
| 108 | command: |
| 109 | - sleep |
| 110 | args: |
| 111 | - infinity |
| 112 | - name: docker |
| 113 | image: docker:24-dind |
| 114 | securityContext: |
| 115 | privileged: true |
| 116 | ''' |
| 117 | } |
| 118 | } |
| 119 | stages { |
| 120 | stage('Build') { |
| 121 | steps { |
| 122 | container('node') { |
| 123 | sh 'npm ci && npm run build' |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | ``` |
| 130 | |
| 131 | ### Labeled Agents |
| 132 | |
| 133 | ```groovy |
| 134 | pipeline { |
| 135 | agent { label 'linux && docker' } |
| 136 | stages { |
| 137 | stage('Build') { |
| 138 | steps { |
| 139 | sh 'make build' |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | ``` |
| 145 | |
| 146 | ## Parameters |
| 147 | |
| 148 | ```groovy |
| 149 | pipeline { |
| 150 | agent any |
| 151 | |
| 152 | parameters { |
| 153 | string(name: 'BRANCH', defaultValue: 'main', description: 'Branch to build') |
| 154 | choice(name: 'ENVIRONMENT', choices: ['dev', 'staging', 'prod'], description: 'Target environment') |
| 155 | booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?') |
| 156 | } |
| 157 | |
| 158 | stages { |
| 159 | stage('Deploy') { |
| 160 | when { |
| 161 | expression { params.ENVIRONMENT == 'prod' } |
| 162 | } |
| 163 | steps { |
| 164 | sh "deploy.sh ${params.ENVIRONMENT}" |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | ``` |
| 170 | |
| 171 | ## Credentials |
| 172 | |
| 173 | ### Using Credentials |
| 174 | |
| 175 | ```groovy |
| 176 | pipeline { |
| 177 | agent any |
| 178 | |
| 179 | environment { |
| 180 | AWS_CREDS = credentials('aws-credentials') |
| 181 | DOCKER_CREDS = credentials('docker-hub') |
| 182 | } |
| 183 | |
| 184 | stages { |
| 185 | stage('Deploy') { |
| 186 | steps { |
| 187 | withCredentials([ |
| 188 | usernamePassword( |
| 189 | credentialsId: 'github-token', |
| 190 | usernameVariable: 'GH_USER', |
| 191 | passwordVariable: 'GH_TOKEN' |
| 192 | ) |
| 193 | ]) { |
| 194 | sh 'git push https://${GH_USER}:${GH_TOKEN}@github.com/repo.git' |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | ``` |
| 201 | |
| 202 | ## Parallel Stages |
| 203 | |
| 204 | ```groovy |
| 205 | pipeline { |
| 206 | agent any |
| 207 | |
| 208 | stages { |
| 209 | stage('Tests') { |
| 210 | parallel { |
| 211 | stage('Unit Tests') { |
| 212 | steps { |
| 213 | sh 'npm run test:unit' |
| 214 | } |
| 215 | } |
| 216 | stage('Integration Tests') { |
| 217 | steps { |
| 218 | sh 'npm run test:integration' |
| 219 | } |
| 220 | } |
| 221 | stage('E2E Tests') { |
| 222 | steps { |
| 223 | sh 'npm run test:e2e' |
| 224 | } |