jenkins pipeline脚本_Jenkins Pipeline脚本

node {

echo 'Hello World'

}

node 在Jenkins环境中分配一个执行器和工作空间。

echo 在控制台输出中写入简单的字符串

try {

timeout(time: 120, unit: 'MINUTES') {

def app_name_prefix="trmserverdev"

// define maven commands

def mvn_cmd = 'mvn -s mvn-settings.xml' //maven配置(nexus/sonar配置)

// define gitlab_project url

def giturl = "http://10.72.76.54/TRM/TRMServer.git"

// define gitlab_project branch

def git_branch = "master"

// define sonar url

def sonarurl = 'http://10.72.76.55:9002'

// define jenkins token

def credentialsId = "dai"

def appName = "${app_name_prefix}"

node {

stage("Initialize") {

project = env.PROJECT_NAME

echo "project: ${project}"

}

}

node("maven") {

stage("Checkout") {

checkout([$class:"GitSCM", branches: [[name: "*/${git_branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${credentialsId}", url: "${giturl}"]]])

}

stage("Unit Test") {

sh "${mvn_cmd} test"

}

stage("Sonar") {

// sh "${mvn_cmd} sonar:sonar -Dsonar.sourceEncoding=UTF-8 -Dsonar.host.url=${sonarurl} -Dsonar.projectName=${appName}-${git_branch} -Dsonar.projectKey=${appName}-${git_branch}"

}

stage("Build WAR") {

sh "${mvn_cmd} clean package"

stash name:"war", includes:"target/TRMServerdev.war" //包名 与项目、镜像名保持一致,附加版本号

}

stage ('Clear Environment') {

sh "rm -rf oc-build && mkdir -p oc-build/deployments"

sh "oc delete bc,dc,svc,route,is -l app=${appName} -n ${project}"

}

stage("Build Image") { //包名 与项目、镜像名保持一致,附加版本号

sh "oc project ${project}"

sh "cp target/TRMServerdev.war oc-build/deployments/"

sh "oc new-build --binary=true --name=${appName} -l app=${appName} -n ${project} --image-stream=openshift/jboss-webserver31-tomcat8-openshift:1.2"

sh "oc start-build ${appName} --from-dir=oc-build --follow=true --wait=true -n ${project}"

}

stage("Deploy") { //URL附加版本号

sh "oc new-app --name=${appName} --image-stream=${appName} --env TZ=Asia/Shanghai"

sh "oc expose svc/${appName} --hostname=${appName}-${project}sit.devapp.cnooc -n ${project}"

}

stage('Integration test') { //自动化测试 jmeter

println 'Starting test'

// TBD: Proper test

println 'Test completed!'

}

//增加发邮件

}

}

} catch (err) {

//完善反馈信息

def comment = "编译失败,错误原因如下:${err} "

//jiraAddComment idOrKey: "${params.issueKey}", comment: comment, site: 'cnooc jira'

//失败状态流转

def transitionInput = [ transition: [id: '81'] ]

//jiraTransitionIssue idOrKey: "${params.issueKey}", input: transitionInput,site: 'cnooc jira'

echo "in catch block"

echo "Caught: ${err}"

currentBuild.result = 'FAILURE'

throw err

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值