jenkins安装

这一生的挚爱 提交于 2020-08-11 03:37:55

一、下载docker镜像
To use the latest LTS: docker pull jenkins/jenkins:lts
To use the latest weekly: docker pull jenkins/jenkins

二、运行docker镜像
docker run -d -u 0 -p 8080:8080 -p 50000:50000 -v /data/jenkins_home:/var/jenkins_home jenkins/jenkins:lts

三、系统初始化密码文件
/data/jenkins_home/secrets/initialAdminPassword

四、python jenkins
pip install python-jenkins
使用文档:http://python-jenkins.readthedocs.io/en/latest/examples.html#example-1-get-version-of-jenkins
创建任务
import jenkins



server = jenkins.Jenkins('http://localhost:8080', username='admin', password='passwd')

job_xml = """<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin='workflow-job@2.17'>
<actions/>
<description>pipeline测试</description>
<keepDependencies>false</keepDependencies>
<properties/>
<definition class='org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition' plugin='workflow-cps@2.45'>
<script>node {
stage('get clone'){
echo 'git clone ......'
}
stage('mvn test'){
echo 'mvn test ......'
}
stage('mvn build'){
echo 'mvn clean install ......'
}
stage('deploy'){
echo 'deploy ......'
}
}</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
<disabled>false</disabled>
</flow-definition>"""
























server.create_job('pipeline测试', job_xml)

五、xml转yaml
pip install jenkins-job-wrecker
https://github.com/ktdreyer/jenkins-job-wrecker

jjwrecker -f path/to/my-job/config.xml -n 'my-job' 文件会生成到当前路径的:"output"文件夹中

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!