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

pipeline {
    agent any
    tools { 
        maven "maven-3.8.1"
    }
    parameters {
        choice(
            choices: 'test\nsit\nglzn\nshenyang\nprod',
            description: 'choose deploy environment',
            name: 'profile_active'
            )
        choice(
            choices: '*/master\n*/develop',
            description: 'choose project branch',
            name: 'proj_branch'
            )            
        string (name: 'version', defaultValue: '1.0.0', description: 'build version')
        choice(
            choices: '192.168.181.83\n192.168.186.6\n192.168.180.218\n192.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"
                    '''
            }
        }
        
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
<properties> <hudson.security.AuthorizationMatrixProperty> <inheritanceStrategy class="org.jenkinsci.plugins.matrixauth.inheritance.InheritParentStrategy"/> <permission>USER:hudson.model.Item.Read:anonymous</permission> </hudson.security.AuthorizationMatrixProperty> <jenkins.model.BuildDiscarderProperty> <strategy class="hudson.tasks.LogRotator"> <daysToKeep>90</daysToKeep> <numToKeep>-1</numToKeep> <artifactDaysToKeep>30</artifactDaysToKeep> <artifactNumToKeep>-1</artifactNumToKeep> </strategy> </jenkins.model.BuildDiscarderProperty> <com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="[email protected]"> <gitLabConnection>src.ift.run</gitLabConnection> <jobCredentialId/> <useAlternativeCredential>false</useAlternativeCredential> </com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty> <com.sonyericsson.rebuild.RebuildSettings plugin="[email protected]"> <autoRebuild>false</autoRebuild> <rebuildDisabled>false</rebuildDisabled> </com.sonyericsson.rebuild.RebuildSettings> <hudson.plugins.throttleconcurrents.ThrottleJobProperty plugin="[email protected]"> <maxConcurrentPerNode>3</maxConcurrentPerNode> <maxConcurrentTotal>0</maxConcurrentTotal> <categories class="java.util.concurrent.CopyOnWriteArrayList"/> <throttleEnabled>true</throttleEnabled> <throttleOption>project</throttleOption> <limitOneJobWithMatchingParams>false</limitOneJobWithMatchingParams> <paramsToUseForLimit/> <configVersion>1</configVersion> </hudson.plugins.throttleconcurrents.ThrottleJobProperty> <jenkins.branch.RateLimitBranchProperty_-JobPropertyImpl plugin="[email protected]_188a_562481"> <durationName>hour</durationName> <count>40</count> <userBoost>true</userBoost> </jenkins.branch.RateLimitBranchProperty_-JobPropertyImpl> </properties> 请解释这一段jenkins配置
07-14

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

it-fans

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值