一、下載下傳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
建立任務
import jenkins
job_xml = """<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin='[email protected]'>
<actions/>
<description>pipeline測試</description>
<keepDependencies>false</keepDependencies>
<properties/>
<definition class='org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition' plugin='[email protected]'>
<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
<a href="https://github.com/ktdreyer/jenkins-job-wrecker">https://github.com/ktdreyer/jenkins-job-wrecker</a>
jjwrecker -f path/to/my-job/config.xml -n 'my-job' 檔案會生成到目前路徑的:"output"檔案夾中
本文轉自aaron428 51CTO部落格,原文連結:http://blog.51cto.com/aaronsa/2082869,如需轉載請自行聯系原作者