Glassfish Payara + jenkins自动部署脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Glassfish Payara + jenkins自动部署脚本相关的知识,希望对你有一定的参考价值。

配置文件内的列需要依次添加
cat AutoDeployConf.conf
#application domain port target contextroot app_name package_path passwordfile
test domain9 4808 test test test /test.war /test_adminpassword.txt

脚本内容,执行方式./auto_deploy_glassfish.sh application
cat auto_deploy_glassfish.sh
#!/bin/bash
. /home/glassfishv4/app_list/glassfishv5_app_list.conf
. /home/glassfishv4/app_list/payara_app_list.conf

rtnCode=0
app_name_param=$1
curr_host=hostname

echo $app_name_param

glassfishv5_asadmin=‘/home/glassfishv4/glassfish5/glassfish/bin/asadmin‘
payara_asadmin=‘/home/glassfishv4/payara41/glassfish/bin/asadmin‘

exec 3<&0 < /home/glassfishv4/AutoDeploy/AutoDeployConf.conf

while read LINE
do
echo "$LINE" | grep "^#" > /dev/null 2>&1 && continue
[ "$LINE" = "" ] || [ "$LINE" = " " ] && continue
application=echo "$LINE" | awk ‘print $1‘
domain_name=echo "$LINE" | awk ‘print $2‘
port=echo "$LINE" | awk ‘print $3‘
target=echo "$LINE" | awk ‘print $4‘
contextroot=echo "$LINE" | awk ‘print $5‘
app_name=echo "$LINE" | awk ‘print $6‘
package_path=echo "$LINE" | awk ‘print $7‘
passwordfile=echo "$LINE" | awk ‘print $8‘

if [ "$application" != "$app_name_param" ]; then
continue;
fi

#done
#exec 0<&3 3<&-

if [[ "$glassfishv5_app_list" =~ $application ]]; then

Undeploy

    $glassfishv5_asadmin --passwordfile $passwordfile --host $curr_host --port $port undeploy --target $target $app_name
    if [ $? -ne 0 ]; then
            echo "Undeploy $application is failure."
            rtnCode=1
            exit $rtnCode
    fi

Shutdown Cluster

    if [ "$target" == "myplm" ]; then
            $glassfishv5_asadmin --passwordfile $passwordfile --host $curr_host --port $port stop-local-instance --node myplm --nodedir /home/glassfishv4/glassfish5/glassfish/nodes $target
            if [ $? -ne 0 ]; then
                    echo "Stop myplm instance is failure"
                    rtnCode=1
            fi
    elif [ "$target" != "server" ]; then
            $glassfishv5_asadmin --passwordfile $passwordfile --host $curr_host --port $port stop-cluster $target
            if [ $? -ne 0 ]; then
                    echo "Stop $target is failure"
                    rtnCode=1
            fi
    fi

Shutdown domain

    $glassfishv5_asadmin stop-domain $domain_name
    if [ $? -ne 0 ]; then
            echo "Stop $domain_name is failure"
            rtnCode=1
    fi

Start domain

    $glassfishv5_asadmin start-domain $domain_name
    if [ $? -ne 0 ]; then
            echo "Start $domain_name is failure"
            rtnCode=1
    fi

Start Cluster

    if [ "$target" == "myplm" ]; then
            $glassfishv5_asadmin --passwordfile $passwordfile --host $curr_host --port $port start-local-instance --node myplm --nodedir /home/glassfishv4/glassfish5/glassfish/nodes $target
            if [ $? -ne 0 ]; then
                    echo "Start myplm instance is failure"
                    rtnCode=1
            fi
    elif [ "$target" != "server" ]; then
            $glassfishv5_asadmin --passwordfile $passwordfile --host $curr_host --port $port start-cluster $target
            if [ $? -ne 0 ]; then
                    echo "Start $target is failure"
                    rtnCode=1
            fi
    fi

Deploy

    $glassfishv5_asadmin --passwordfile $passwordfile --host $curr_host --port $port deploy --name $app_name --contextroot $contextroot --target $target $package_path
    if [ $? -ne 0 ]; then
            echo "Deploy $application is failure"
            rtnCode=1
            exit $rtnCode
    fi

elif [[ "$payara_app_list" =~ $app_name_param ]]; then

    $payara_asadmin --passwordfile $passwordfile --host $curr_host --port $port undeploy --target $target $app_name
    if [ $? -ne 0 ]; then
            echo "Undeploy $application is failure."
            rtnCode=1
            exit $rtnCode
    fi

    if [ "$target" != "server" ]; then
            $payara_asadmin --passwordfile $passwordfile --host $curr_host --port $port stop-cluster $target
            if [ $? -ne 0 ]; then
                    echo "Stop $target is failure"
                    rtnCode=1
            fi
    fi

    $payara_asadmin stop-domain $domain_name
    if [ $? -ne 0 ]; then
            echo "Stop $domain_name is failure"
            rtnCode=1
    fi

    $payara_asadmin start-domain $domain_name
    if [ $? -ne 0 ]; then
            echo "Start $domain_name is failure"
            rtnCode=1
    fi

    if [ "$target" != "server" ]; then
            $payara_asadmin --passwordfile $passwordfile --host $curr_host --port $port start-cluster $target
            if [ $? -ne 0 ]; then
                    echo "Start $target is failure"
                    rtnCode=1
            fi
    fi

    $payara_asadmin --passwordfile $passwordfile --host $curr_host --port $port deploy --name $app_name --contextroot $contextroot --target $target $package_path
    if [ $? -ne 0 ]; then
            echo "Deploy $application is failure"
            rtnCode=1
            exit $rtnCode
    fi

else
echo "There is no the application."
fi

done
exec 0<&3 3<&-

exit $rtnCode

整个过程就是undeploy--stop cluster--stop domain--start domain--start cluster--deploy
具体语法可以在官网直接找到

将脚本信息及war位置配置在jenkins里即可实现自动部署

以上是关于Glassfish Payara + jenkins自动部署脚本的主要内容,如果未能解决你的问题,请参考以下文章

Glassfish+Payara自动化安装脚本!!

如何将 Hibernate 配置为 Payara/Glassfish 4.1 的 JPA 提供程序? [关闭]

org.jboss.weld.exceptions.DefinitionException:在payara / glassfish中部署时的WELD-001113

升级到 payara 4.1.1.171 后应用程序未加载

包含EJB的Java 8 Compiled EAR导致Payara中的java.lang.NoClassDefFoundError

Payara Server 错误:找不到或无法加载主类[9]--add-opens-java.logging.java.util.logging-ALL-UNNAMED