jenkins添加新服务
- 新建item
- 添加流水线
node{
def envname = "ENVIRONMENT:1234-dev"
def projectGitUrl = 'http://xxxxx/xxxxxx/12345.git'
def imageServer = 'harbor.xxxxx.com' //镜像仓库地址
def projectAppName = '12345-application'
def projectGitBranch = 'dev'//git分支
def projectBaseVersion = '12341.2'
def projectAppPort = "9112"
def namespace = "1234-uat" //跟随分支变化而变化
def imageLibrary = '1234'//dev环境是:xxxx-dev,pre环境:sf-pre
def prefix ="ms" //dev环境:ms pre环境:pre-ms
def imageServerSecret = "1234"//固定
def projectAppNickName = "${prefix}-${projectAppName}"
def buildVersion = "${projectBaseVersion}.${BUILD_NUMBER}"
def dockerImageName = "${imageServer}/${imageLibrary}/${projectAppNickName}"
def dockerImageFullName = "${dockerImageName}:${buildVersion}"
def replicas = "1"
timestamps {
try {
stage('check out') {
checkout([$class: 'GitSCM', branches: [[name: "${projectGitBranch}"]], extensions: [],
userRemoteConfigs: [[credentialsId: 'git-sf-credentials',
url: "${projectGitUrl}"]]])
}
stage('build image') {
sh "docker build -t ${dockerImageFullName} -f ./12345-adapter/Dockerfile ."
}
stage("publish image") {
sh "docker push ${dockerImageFullName}"
}
stage("deploy kubernetes") {
// sh " /u01/sie/deployApp-test.sh --appname=${projectAppNickName} --image=${dockerImageName} --version=${buildVersion} --namespace=${namespace} --replicas=${replicas} --serviceport=${projectAppPort} --secretkey=${imageServerSecret} --envname=${envname}"
sh "/usr/bin/kubectl --kubeconfig /root/.kube/config set image deployment/${projectAppNickName} ${projectAppNickName}=${dockerImageFullName} --namespace=${namespace}"
}
}catch (err) {
deleteDir()
currentBuild.result = 'FAILURE'
} finally {
//influxDbPublisher(selectedTarget: 'Jenkins构建结果收集')
}
}
}
异常信息
解决不对
stage('build image') {
sh "docker build -t ${dockerImageFullName} -f ./mdfp-intel-audit-adapter/Dockerfile ."
}
对应rancher命名空间错了
def namespace = "mxbc-dev" //跟随分支变化而变化