快捷搜索: 王者荣耀 脱发

Jenkins流水线脚本与cat > file <<EOF结合使用案例

pipeline { agent any tools { maven "maven-3.8.1" } parameters { choice( choices: test sit glzn shenyang prod, description: choose deploy environment, name: profile_active ) choice( choices: */master */develop, description: choose project branch, name: proj_branch ) string (name: version, defaultValue: 1.0.0, description: build version) choice( choices: 192.168.181.83 192.168.186.6 192.168.180.218 192.168.181.52, description: choose file server, name: file_server_ip ) } environment { image_path = "/data/glzn" image_tag = "${profile_active}${version}-" file_path = "/data/app/files/iot-core/${image_tag}" image_repo = "192.168.180.204:19080/iot" os_type = "x86" proj_repo = "http://192.168.180.148/rdc/rule-engine.git" credentials_id = "366f3dc5-074e-4338-8a96-32db1990b9fbx" } stages { stage(Check out) { steps { checkout([$class: GitSCM, branches: [[name: "${proj_branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${credentials_id}", url: "${proj_repo}"]]]) } } stage(Deploy Proj) { steps { sh app_name=rule-engine-app mvn clean package -P ${profile_active} -Dmaven.test.skip=true mv -f application/target/$app_name.jar ${image_path}/$app_name/app.jar cd ${image_path}/$app_name cat > Dockerfile <<-EOF FROM 192.168.200.17/software/jre11:openjdk11 LABEL maintainer Ron VOLUME /tmp RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime COPY app.jar / ENV JAVA_OPTS="-Dname=rule-engine-app -Duser.timezone=GMT+08 -Dfile.encoding=UTF8 -Dfastjson.parser.safeMode=true" ENTRYPOINT exec java $JAVA_OPTS ${JVM:=-Xms512m -Xmx2048m} -jar /app.jar EOF date=`date +%Y%m%d` image_name=${image_repo}/$app_name/${os_type}:${image_tag}$date docker build -t $image_name . && docker images docker push $image_name docker save -o $app_name.tar $image_name tar -zcvf $app_name.tar.gz $app_name.tar rm -rf $app_name.tar && docker rmi $image_name

ansible $file_server_ip -m shell -a "mkdir -p ${file_path}$date" ansible $file_server_ip -m copy -a "src=$app_name.tar.gz dest=${file_path}$date/$app_name.tar.gz" ansible $file_server_ip -m shell -a "echo $image_name > ${file_path}$date/$app_name.txt" } } } }

经验分享 程序员 微信小程序 职场和发展