Jenkinsfile
def deployIp = '192.168.1.53' def remote = [:] remote.name = deployIp remote.host = deployIp remote.user = 'root' remote.password = LCX_PWD_5s remote.allowAnyHosts = true def gitUrl = 'http://192.168.1.43:8600/bigdata/flink-streaming.git' def gitBranch = 'lcx-20230208' def jarPath = 'target' def propertiesPath = 'src/main/resources' def jarName = 'flink-streaming-1.0-SNAPSHOT.jar' def propertiesName = 'app-gas-4s.properties' def deployPath = '/lcx/kafka2ck-gas-4s' def flinkPath = '/opt/flink/gas-4s' def flinkContainerName = 'data_jobmanager_1' def className = 'com.gmr.cloud.streaming.source.NewGasGaeStreaming' def jobName = 'kafka2ck_gae_4s' pipeline { agent any stages { stage('pull code') { steps { checkout([$class: 'GitSCM', branches: [[name: "*/${gitBranch}"]], extensions: [], userRemoteConfigs: [[credentialsId: LCX_GIT_AUTH_ID, url: gitUrl]]]) } } stage('package') { steps { sh """ mvn clean package -Dmaven.test.skip=true """ } } stage('scp') { steps { sh """ scp ${jarPath}/${jarName} root@${deployIp}:${deployPath}/ scp ${propertiesPath}/${propertiesName} root@${deployIp}:${deployPath}/ """ } } stage('docker cp') { steps { sshCommand remote: remote, command: """ cd ${deployPath} docker cp ${jarName} ${flinkContainerName}:${flinkPath}/ docker cp ${propertiesName} ${flinkContainerName}:${flinkPath}/ """ } } stage('flink stop') { steps { sshCommand remote: remote, command: """ docker exec -i ${flinkContainerName} flink list | grep ${jobName} | awk '{print \$4}' | xargs -n1 docker exec -i ${flinkContainerName} flink cancel """ } } stage('flink run') { steps { sshCommand remote: remote, command: """ cd ${deployPath} rm -rf start.log nohup docker exec -i ${flinkContainerName} flink run -c ${className} ${flinkPath}/${jarName} ${flinkPath}/${propertiesName} >${deployPath}/start.log 2>&1 & sudo ls """ } } } }
第一个坑:flink run 执行后 jenkins 任务一直不结束
在linux命令行运行 flink run ,的确命令不会退出,然后我在命令结尾处加了 & 符号,命令行看样子是退出了,于是我直接改 Jenkinsfile ,再次构建,构建任务依然无法结束
最后我自己手动结束了构建任务
回到命令行又试了一次,发现很奇怪的现象,上面的命令输入后,虽然很快就退出了,但是接下来不管我再输入一行什么任何其他命令,命令的结尾都会显示已停止字样,
虽然不知道为什么会这样,但是我想我需要在 Jenkinsfile 这行命令的后面任意的再加一行其他无关紧要的命令,才能让构建任务顺利退出
果然,多加一行 ls 命令后,jenkins 构建任务成功结束了
坑二:停止 job 的命令总是报错
日志总是提示 $ 符号用的不对,改成 \$ 也还是报错,一直不懂为啥其他地方可以用 ${} 而这里不能用,最后仔细的看了下错误提示,发现好像是让我注意转义 $ 符号,用百度翻译后,发现的确是提示我注意 $ 符号要转义,只是他提示我的地方不对,真正有问题的是 $4 这个地方,应该写成 \$4
这个坑谁也怪不了,只能怪自己英文不好
标签:remote,flink,steps,job,flinkContainerName,jenkins,def,stage From: https://www.cnblogs.com/LcxSummer/p/17481012.html