https://www.jianshu.com/p/845f267aec52
我们常刚使用jenkins pipline的时候不知道语法命令怎么写,其实几个命令在jenkins上都有说明
点击生成流水线脚本即可,非常easy
pipline实例:
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
git branch: 'dmp-2.5', credentialsId: 'at', url: 'http://(marked)/tfs/GS7/_git/BA-DMP'
}
}
stage('build'){
steps{
sh "pwd"
sh "mvn clean package -f dmp-datafactory/pom.xml"
}
}
}
}
node {
def mvnHome
stage('Preparation') { // for display purposes
cleanWs()
}
stage('Build') {
// writeFile encoding: 'utf-8', file: 'a.txt', text: 'haha'
def envList=['oracle','ms','dm','my57','my8','pg','oscar','highgo','kingbase']
for (String s : envList) {
sh 'echo '+s
if(!fileExists(s)){
sh "mkdir "+s
sh "cp /root/.jenkins/workspace/dmp2103/dmp-datafactory/target/dmp-datafactory.jar ./"+s
sh "cp /root/.jenkins/workspace/dmp2103/dmp-datafactory/src/main/resources/*.properties ./"+s
sh "cp /root/.jenkins/workspace/dmp2103/dmp-datafactory/src/main/resources/*.dmp ./"+s
sh "cp -r /root/.jenkins/workspace/dmp2103/sqls/dbdir ./"+s
sh "cp /root/.jenkins/workspace/dmp2103/dmp-datafactory/docker/docker-compose.yml ./"
}
}
sh "mkdir premachine"
sh "cp /root/.jenkins/workspace/dmp2103/PreposedMachine/target/preposed-machine.jar ./premachine/"
withEnv(['JENKINS_NODE_COOKIE=background_job']){
sh "docker-compose down"
sh "docker-compose up -d"
}
}
stage('Results') {
echo "end"
}
}
node {
def mvnHome
stage('cleanWorkspace') {
cleanWs()
}
stage('Preparation') {
cleanWs()
// for display purposes
// Get some code from a GitHub repository feature/2103tablemerge dmp-2103
git branch: 'dmp-2103', credentialsId: 'at', url: 'http://tfs.inspur.com:8080/tfs/GS7/_git/BA-DMP'
// Get the Maven tool.
// ** NOTE: This 'M3' Maven tool must be configured
// ** in the global configuration.
mvnHome = tool 'M3'
}
stage('Build') {
sh "pwd"
timeout(30) {
// Run the maven build
withEnv(["MVN_HOME=$mvnHome"]) {
if (isUnix()) {
sh '"$MVN_HOME/bin/mvn" -Dmaven.test.failure.ignore clean package -f ./dmp-datafactory/pom.xml'
sh '"$MVN_HOME/bin/mvn" -Dmaven.test.failure.ignore clean package -f ./PreposedMachine/pom.xml'
} else {
bat(/"%MVN_HOME%\bin\mvn" -Dmaven.test.failure.ignore clean package -f dmp-datafactory\\pom.xml /)
}
}
}
}
stage('Results') {
echo "finished"
// junit '**/target/surefire-reports/TEST-*.xml'
archiveArtifacts 'dmp-datafactory/target/*.jar'
archiveArtifacts 'PreposedMachine/target/*.jar'
}
}