jenkins pipline demo

pipline demo https://jenkins.io/zh/doc/book/pipeline/syntax/ git 插件 https://jenkins.io/doc/pipeline/steps/git/ pipline pipeline{ agent any stages{ stage("build"){ steps{ echo "11111" } } } } pipeline总体介绍 基本结构 以下每一个部分都是必须的,少一个Jenkins都会报错 pipline pipeline{ agent any stages{ stage("build"){ steps{ echo "hellp" } } } } pipeline 代表整个流水线,包含整条流水线的逻辑 stage 阶段,代表流水线的阶段,每个阶段都必须有名称。 stages 流水线中多个stage的容器,stages部分至少包含一个stage. steps 代表stage中的一个活多个具体步骤的容器,steps部分至少包含一个步骤 agent 制定流水线的执行位置,流水线中每个阶段都必须在某个地方执行(master节点/slave节点/物理机/虚拟机/docker容器),agent部分指定具体在哪里执行。agent { label '***-slave'} 可选步骤 post 包含的是在整个pipeline或stage完成后的附件条件 always 论Pipeline运行的完成状态如何都会执行这段代码 changes 只有当前Pipeline运行的状态与先前完成的Pipeline的状态不同时,才能触发运行。 failure 当前状态为失败时执行 success 当前完成状态为成功时执行 demo 使用${test},可以引入自定义变量 pipeline post { always { script { allure includeProperties: false, jdk: '',report: 'jenkins-allure-report', results: [[path: 'allure-results']] } } failure { script { if (gitpuller == 'noerr') { mail to: "${email_list}", subject: "[jenkins Build Notification] ${JOB_NAME} - Build # ${BUILD_NUMBER} 构建失败", body: "'${env....

 ·  · 

jenkins的用户授权与管理

需要安装的插件 Role-Based Strategy(可以对构建的项目进行授权管理,让不同的用户管理不同的项目,将测试和生产环境分开) 选择授权策略 当Role-based Authorization Strategy 这个插件安装好之后,授权策略会多出一个Role-Based Strategy 选项,选择此项 添加配置权限 系统设置 » Manage and Assign Roles Manage Roles 设置全局角色(全局角色可以对jenkins系统进行设置与项目的操作) admin:对整个jenkins都可以进行操作 root:可以对所有的job进行管理 other:只有读的权限 other必须有,否则给用户分配角色时分配没有全局role会导致分配失效 Assign Roles为用户指派角色 项目角色是根据正则匹配的,

 ·  · 

jenkins历史比较

文中的代码来自可以从github下载: https://github.com/ciandcd 插件 jobConfigHistory,可以查看job配置的修改历史。 安装后重启jenkins,然后对job的配置修改后,可以点击job config history连接查看修改历史。 选择需要比较的版本,可以diff两个版本间的差别。

 ·  · 

jenkins在Mac OS下的迁移记录

修改启动用户 先停止jenkins服务 sh 1 2 sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist sudo vim /Library/LaunchDaemons/org.jenkins-ci.plist 授权jenkins工作目录和临时目录 text 1 2 sudo chown -R zhulangren:wheel /Users/Shared/Jenkins/ sudo chown -R zhulangren:wheel /var/log/jenkins/ 启动jenkins text 1 sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist jenkins自启动文件路径 text 1 /Library/LaunchDaemons/org.jenkins-ci.plist 卸载脚本文件 text 1 /Library/Application\ Support/Jenkins/Uninstall.command 修改jenkins启动端口 text 1 sudo defaults write /Library/Preferences/org.jenkins-ci httpPort '9999' 读取jenkins配置文件 text 1 defaults read /Library/Preferences/org.jenkins-ci 设置自启动 text 1 sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plis 取消自启动 text 1 sudo launchctl unload /Library/LaunchDaemons/org....

 ·  · 

jenkins pipeline docker方式

pipline def timestr() { script { return sh(script: 'date +%Y%m%d%H%M%S', returnStdout: true).trim() } } def dockerImage pipeline{ agent any environment { time = timestr() registry = "xxx.com/payapp-test" registryhub = "txhub.xxx.com" appName = "api" } options { timeout(time: 1, unit: 'HOURS') buildDiscarder(logRotator(numToKeepStr: '15')) disableConcurrentBuilds() } stages{ stage("Pull Code"){ steps{ git branch: 'testing', credentialsId: '422fb2c7-4d58-440a-98a4-e242b66f3800', url: 'http://gitlab.fgry45iy.com:90/pay/payGateway.git' } } stage("Maven Package"){ steps{ withEnv(['PATH+EXTRA=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/apache-maven-3.6.2/bin:/usr/local/maven/bin:/root/bin']) { sh "mvn package" } } } // stage('Building Image') { // steps{ // script { // dockerImage = docker....

 ·  ·