jenkins-pipelines

jenkins-pipelines:用于构建和管理 Jenkins CI/CD 流水线。适用于编写 Jenkinsfile、配置声明式或脚本化流水线、多分支流水线、管理代理与节点、配置共享库、与 Docker/Kubernetes/云服务集成、设置 Webhook 与触发器、管理凭据与密钥,以及排查构建失败问题。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
7

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "jenkins-pipelines":https://skillpi.com/zh/skills/deepskill-45cf679f27a6573bd27b104edf48f768fe17e9ea22f0a18e22abd6805554336e。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

jenkins-pipelines:用于构建和管理 Jenkins CI/CD 流水线。适用于编写 Jenkinsfile、配置声明式或脚本化流水线、多分支流水线、管理代理与节点、配置共享库、与 Docker/Kubernetes/云服务集成、设置 Webhook 与触发器、管理凭据与密钥,以及排查构建失败问题。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: jenkins-pipelines
description: >-
  Builds and manages Jenkins CI/CD pipelines. Use when the user wants to
  write Jenkinsfiles, configure declarative or scripted pipelines, set up
  multibranch pipelines, manage Jenkins agents and nodes, configure shared
  libraries, integrate with Docker/Kubernetes/cloud providers, set up
  webhooks and triggers, manage credentials and secrets, or troubleshoot
  build failures. Trigger words: jenkins, jenkinsfile, jenkins pipeline,
  jenkins agent, jenkins node, jenkins shared library, jenkins docker,
  jenkins kubernetes, multibranch pipeline, jenkins credentials, jenkins
  webhook, jenkins groovy, jenkins blue ocean, jenkins job dsl.
license: Apache-2.0
compatibility: "Jenkins 2.400+ with Pipeline plugin. Java 11+ or 17+ for Jenkins controller."
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: devops
  tags: ["jenkins", "ci-cd", "pipelines", "automation"]

Jenkins Pipelines

Overview

Creates and manages Jenkins CI/CD pipelines using both Declarative and Scripted syntax. Covers Jenkinsfile authoring, multibranch pipelines, shared libraries, Docker and Kubernetes agents, credential management, parallel execution, artifact handling, notifications, and production-grade pipeline patterns.

Instructions

1. Declarative Pipeline

pipeline {
    agent {
        docker {
            image 'node:20-alpine'
            args '-v $HOME/.npm:/root/.npm'
        }
    }
    options {
        timeout(time: 30, unit: 'MINUTES')
        disableConcurrentBuilds()
        buildDiscarder(logRotator(numToKeepStr: '20'))
        timestamps()
    }
    environment {
        APP_NAME = 'api-server'
        REGISTRY = 'registry.example.com'
        IMAGE = "${REGISTRY}/${APP_NAME}"
    }
    stages {
        stage('Install') { steps { sh 'npm ci' } }
        stage('Lint & Test') {
            parallel {
                stage('Lint') { steps { sh 'npm run lint' } }
                stage('Unit Tests') {
                    steps { sh 'npm test -- --coverage' }
                    post { always { junit 'reports/junit.xml' } }
                }
                stage('Security') { steps { sh 'npm audit --audit-level=high' } }
            }
        }
        stage('Build Image') {
            steps {
                script {
                    def tag = env.GIT_COMMIT.take(8)
                    docker.build("${IMAGE}:${tag}")
                    docker.withRegistry("https://${REGISTRY}", 'registry-credentials') {
                        docker.image("${IMAGE}:${tag}").push()
                        docker.image("${IMAGE}:${tag}").push('latest')
                    }
                }
            }
        }
        stage('Deploy Staging') {
            when { branch 'main' }
            steps {
                withCredentials([file(credentialsId: 'kubeconfig-staging', variable: 'KUBECONFIG')]) {
                    sh "helm upgrade --install ${APP_NAME} ./charts/${APP_NAME} -n staging --set image.tag=${GIT_COMMIT.take(8)} --wait"
                }
            }
        }
        stage('Deploy Production') {
            when { branch 'main' }
            input { message 'Deploy to production?'; ok 'Deploy'; submitter 'admin,platform-team' }
            steps {
                withCredentials([file(credentialsId: 'kubeconfig-prod', variable: 'KUBECONFIG')]) {
                    sh "helm upgrade --install ${APP_NAME} ./charts/${APP_NAME} -n production --set image.tag=${GIT_COMMIT.take(8)} --wait --timeout 10m"
                }
            }
        }
    }
    post {
        success { slackSend(channel: '#deployments', color: 'good', message: "Deployed: ${env.BUILD_URL}") }
        failure { slackSend(channel: '#deployments', color: 'danger', message: "Failed: ${env.BUILD_URL}") }
        always { cleanWs() }
    }
}

2. Multibranch Pipeline

// Branch-specific behavior
stage('Deploy') {
    when {
        anyOf {
            branch 'main'
            branch pattern: 'release/.*', comparator: 'REGEXP'
        }
    }
    steps { /* deploy */ }
}
stage('PR Checks') {
    when { changeRequest() }
    steps {
        githubNotify(status: 'PENDING', description: 'Running checks')
        sh 'npm test'
    }
    post {
        success { githubNotify(status: 'SUCCESS') }
        failure { githubNotify(status: 'FAILURE') }
    }
}

3. Shared Libraries

vars/
├── buildDockerImage.groovy
├── deployToK8s.groovy
└── notifySlack.groovy

vars/buildDockerImage.groovy:

def call(Map config) {
    def tag = config.tag ?: env.GIT_COMMIT.take(8)
    def registry = config.registry ?: 'registry.example.com'
    def image = "${registry}/${config.name}:${tag}"
    stage('Build Image') {
        docker.build(image, "-f ${config.dockerfile ?: 'Dockerfile'} .")
        docker.withRegistry("https://${registry}", config.credentialsId ?: 'registry-creds') {
            docker.image(image).push()
            if (env.BRANCH_NAME == 'main') docker.image(image).push('latest')
        }
    }
    return image
}

Usage:

@Library('company-pipeline-lib') _
pipeline {
    agent any
    stages {
        stage('Build') {
            steps { script { def image = buildDockerImage(name: 'api-server') } }
        }
    }
    post { always { notifySlack() } }
}

4. Kubernetes Agents

pipeline {
    agent {
        kubernetes {
            yaml '''
apiVersion: v1
kind: Pod
spec:
  containers:
    - name: node
      image: node:20-alpine
      command: ['sleep', '99d']
    - name: docker
      image: docker:24-dind
      securityContext: { privileged: true }
    - name: helm
      image: alpine/helm:3.14
      command: ['sleep', '99d']
'''
            defaultContainer 'node'
        }
    }
    stages {
        stage('Build') { steps { sh 'npm ci && npm run build' } }
        stage('Docker') { steps { container('docker') { sh 'docker build -t myapp .' } } }
        stage('Deploy') { steps { container('helm') { sh 'helm upgrade --install myapp ./charts/myapp' } } }
    }
}

5. Credentials Management

// Username/password
withCredentials([usernamePassword(credentialsId: 'db-creds', usernameVariable: 'DB_USER', passwordVariable: 'DB_PASS')]) {
    sh 'psql -U $DB_USER -h db.example.com'
}

// Secret text
withCredentials([string(credentialsId: 'api-key', variable: 'API_KEY')]) {
    sh 'curl -H "Authorization: Bearer $API_KEY" https://api.example.com'
}

// SSH key
withCredentials([sshUserPrivateKey(credentialsId: 'deploy-key', keyFileVariable: 'SSH_KEY', usernameVariable: 'SSH_USER')]) {
    sh 'ssh -i $SSH_KEY $SSH_USER@server.example.com "deploy.sh"'
}

// File (kubeconfig)
withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {
    sh 'kubectl get pods'
}

6. Pipeline Patterns

Retry and error handling:

stage('Deploy') {
    steps {
        retry(3) { timeout(time: 5, unit: 'MINUTES') { sh 'deploy.sh' } }
    }
    post { failure { sh 'rollback.sh' } }
}

Stash/unstash artifacts:

stage('Build') {
    steps { sh 'npm run build'; stash includes: 'dist/**', name: 'build-artifacts' }
}
stage('Deploy') {
    agent { label 'deploy-node' }
    steps { unstash 'build-artifacts'; sh 'deploy.sh dist/' }
}

Examples

Example 1: Monorepo Pipeline

Input: "Monorepo with 4 services (api, web, worker, shared-lib). Build only changed services. If shared-lib changes, rebuild all dependents. Deploy changed services independently."

Output: Jenkinsfile with git diff changeset detection, parallel build stages per changed service, dependency graph for shared-lib, independent Helm deploys with separate image tags, and shared library for common steps.

Example 2: Jenkins on Kubernetes with Auto-Scaling

Input: "Jenkins on EKS. Controller as StatefulSet with persistent storage. Ephemeral pod agents with 3 templates: node (JS), python (ML), docker (image builds)."

Output: Helm deployment of Jenkins controller with PVC, JCasC configuring Kubernetes cloud with 3 pod templates and resource limits, shared PVC for npm/Maven cache, RBAC ServiceAccount for pod creation.

Guidelines

  • Use Declarative syntax unless you need complex Groovy logic
  • Always set timeout and disableConcurrentBuilds in options
  • Use cleanWs() in post-always to prevent disk space issues
  • Keep Jenkinsfiles in the repository, not configured in Jenkins UI
  • Use shared libraries for common patterns — avoid copy-pasting
  • Use withCredentials — never hardcode secrets
  • Prefer Docker or Kubernetes agents over permanent agents
  • Use when conditions to skip unnecessary stages on branches/PRs
  • Archive test reports with junit step for trend tracking
  • Set up Jenkins Configuration as Code (JCasC) — no manual UI configuration

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值95/100

亮点

  • Jenkins CI/CD流水线构建和管理是高价值DevOps核心场景
  • 覆盖声明式/脚本化流水线、多分支流水线、共享库、Docker/Kubernetes集成等完整功能
  • 提供生产级流水线模式和最佳实践指导
触发精准90/100

亮点

  • 触发词覆盖全面,包含jenkins、jenkinsfile、pipeline、agent、credentials等关键术语
  • 边界清晰,准确描述Jenkins相关场景
  • 支持多种变体表达,如multibranch pipeline、jenkins webhook等
结构规范95/100

亮点

  • 结构清晰,包含Overview、Instructions、Examples、Guidelines完整章节
  • 提供端到端示例,涵盖Monorepo Pipeline和Kubernetes部署场景
  • frontmatter完整,包含兼容性说明和元数据
  • 代码示例丰富且规范,覆盖Declarative Pipeline、Shared Libraries、Kubernetes Agents等
执行可靠90/100

亮点

  • 工具来源明确,使用标准Jenkins Pipeline语法
  • 参数配置正确,包含timeout、disableConcurrentBuilds等生产级选项
  • 覆盖主要异常处理,如retry、post failure处理
  • 不可逆操作有确认机制,如生产部署需要input确认
证据可验 (前四项均值)93/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • api.example.com

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。