<#if pub.getPSDeployCenter()?? && sysrun.getRunMode()??>
<#if pub.getPSDeployCenter().getCIType()?? && (pub.getPSDeployCenter().getCIType()=="JENKINS") >
<#if sysrun.getRunMode() == "STARTMSAPI">
<#assign depapi = sysrun.getPSDevSlnMSDepAPI()>
<#assign configId = depapi.getId()>
<#assign config = "api"+depapi.getName()>
<#assign depnode = sysrun.getPSDevSlnMSDepAPI().getPSDCMSPlatformNode()>
<#assign depplatform = sysrun.getPSDevSlnMSDepAPI().getPSDCMSPlatform()>
<#elseif sysrun.getRunMode() == "STARTMSAPP">
<#assign depapp = sysrun.getPSDevSlnMSDepApp()>
<#assign configId = depapp.getId()>
<#assign config = "app"+depapp.getName()>
<#assign depnode = sysrun.getPSDevSlnMSDepApp().getPSDCMSPlatformNode()>
<#assign depplatform = sysrun.getPSDevSlnMSDepApp().getPSDCMSPlatform()>
</#if>
<#if sys.getPSSVNInstRepo().getGitBranch()?? && sys.getPSSVNInstRepo().getGitBranch()!="">
      <#assign branch=sys.getPSSVNInstRepo().getGitBranch()>
    <#else>
      <#assign branch='master'>
</#if>
<?xml version='1.1' encoding='UTF-8'?>
<project>
  <actions/>
  <description>${sys.codeName}</description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <hudson.model.ParametersDefinitionProperty>
      <parameterDefinitions>
        <hudson.model.StringParameterDefinition>
          <name>para1</name>
          <description></description>
          <defaultValue>para1</defaultValue>
          <trim>false</trim>
        </hudson.model.StringParameterDefinition>
        <hudson.model.StringParameterDefinition>
          <name>para2</name>
          <description></description>
          <defaultValue>para2</defaultValue>
          <trim>false</trim>
        </hudson.model.StringParameterDefinition>        
      </parameterDefinitions>
    </hudson.model.ParametersDefinitionProperty>
  </properties>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers/>
  <concurrentBuild>false</concurrentBuild>
  <builders>
    <hudson.tasks.Shell>
      <command>
      BUILD_ID=DONTKILLME
      source /etc/profile
      rm -rf ${sys.codeName?lower_case}
	  git clone -b ${branch} $para2 ${sys.codeName?lower_case}/
      export NODE_OPTIONS=--max-old-space-size=4096
      cd ${sys.codeName?lower_case}/
<#if sysrun.getRunMode() == "STARTMSAPP">      
<#if pub.getPSDeployCenter().getCDType()?? && (pub.getPSDeployCenter().getCDType()=="SWARM") >      
      mkdir -p /var/lib/jenkins/appcache/${depapp.getId()}
      cd app_${pub.getPSApplication().getPKGCodeName()}/app
      yarn
      ln -s /var/lib/jenkins/appcache/${depapp.getId()} node_modules/.cache
      yarn build
      cd ..
      yarn
      yarn build
      rm -rf app
      tar -zcvf docker/{{projectName}}-app-${pub.getPSApplication().getPKGCodeName()?lower_case}.tar.gz --exclude=docker * > /dev/null
      cd docker
      docker build -t registry.cn-shanghai.aliyuncs.com/ibizsys/{{projectName}}-app-${pub.getPSApplication().getPKGCodeName()?lower_case}:latest .
      docker push registry.cn-shanghai.aliyuncs.com/ibizsys/{{projectName}}-app-${pub.getPSApplication().getPKGCodeName()?lower_case}:latest
      docker -H $para1 stack deploy --compose-file=swarm.yaml ${depplatform.getName()} --with-registry-auth
<#elseif  pub.getPSDeployCenter().getCDType()?? && (pub.getPSDeployCenter().getCDType()=="K8S") >
      cd app_${pub.getPSApplication().getPKGCodeName()}/app
      yarn
      yarn build
      cd ..
      yarn
      yarn build
      rm -rf app
      tar -zcvf docker/{{projectName}}-app-${pub.getPSApplication().getPKGCodeName()?lower_case}.tar.gz * > /dev/null
      cd docker
      docker build -t registry.cn-shanghai.aliyuncs.com/ibizsys/{{projectName}}-app-${pub.getPSApplication().getPKGCodeName()?lower_case}:latest .
      docker push registry.cn-shanghai.aliyuncs.com/ibizsys/{{projectName}}-app-${pub.getPSApplication().getPKGCodeName()?lower_case}:latest
      set +e
      kubectl --kubeconfig ~/shanghai-demo-01 delete -f k8s.yaml -n ${depplatform.getName()?lower_case}
      set -e
      kubectl --kubeconfig ~/shanghai-demo-01 create -f k8s.yaml -n ${depplatform.getName()?lower_case}
<#else>
      echo &apos;echo &quot;$para1&quot;&apos; &gt; apppasswd.sh
      chmod -R 777 *
      setsid env SSH_ASKPASS=&apos;./apppasswd.sh&apos; DISPLAY=&apos;none:0&apos; ssh ${depnode.getSSHUserName()}@${depnode.getSSHIPAddr()} &quot;mkdir -p ${depnode.getWorkshopPath()}/${configId}&quot;
      setsid env SSH_ASKPASS=&apos;./apppasswd.sh&apos; DISPLAY=&apos;none:0&apos; scp -r {{projectName}}-app-${pub.getPSApplication().getPKGCodeName()?lower_case}.jar ${depnode.getSSHUserName()}@${depnode.getSSHIPAddr()}:${depnode.getWorkshopPath()}/${configId}
      setsid env SSH_ASKPASS=&apos;./apppasswd.sh&apos; DISPLAY=&apos;none:0&apos; ssh ${depnode.getSSHUserName()}@${depnode.getSSHIPAddr()} &quot;ps -ef | grep &apos;${depnode.getWorkshopPath()}/${configId}&apos;| tr -s &apos; &apos;|cut -d&apos; &apos; -f2,8,9  | grep -v grep | grep &apos;jar&apos; | cut -d&apos; &apos; -f1|xargs  --no-run-if-empty kill -9&quot;
      setsid env SSH_ASKPASS=&apos;./apppasswd.sh&apos; DISPLAY=&apos;none:0&apos; ssh ${depnode.getSSHUserName()}@${depnode.getSSHIPAddr()} &quot;source /etc/profile;source ~/.bash_profile; nohup java -jar -Xms512m -Xmx1024m -XX:PermSize=128M -XX:MaxPermSize=128m ${depnode.getWorkshopPath()}/${configId}/{{projectName}}-app-${pub.getPSApplication().getPKGCodeName()?lower_case}.jar &gt;&gt;${depnode.getWorkshopPath()}/${configId}/${sys.codeName?lower_case}_${config?lower_case}-`date --date=&apos;0 days ago&apos; +%Y-%m-%d`.log 2&gt;&amp;1 &amp;&quot;
</#if>
</#if>
<#if sysrun.getRunMode() == "STARTMSAPI">      
      mvn clean package -P${pub.getPSSysServiceAPI().getCodeName()?lower_case}
      mvn install -P${pub.getPSSysServiceAPI().getCodeName()?lower_case}
<#if pub.getPSDeployCenter().getCDType()?? && (pub.getPSDeployCenter().getCDType()=="SWARM") >           
      cd {{projectName}}-provider
<#if depapi.getUserParam("multiplatform","")?? && depapi.getUserParam("multiplatform","")=="true">   
      mvn -P${pub.getPSSysServiceAPI().getCodeName()?lower_case} exec:exec@prepare
      mvn -P${pub.getPSSysServiceAPI().getCodeName()?lower_case} exec:exec@buildpush      
<#else>   
      mvn -P${pub.getPSSysServiceAPI().getCodeName()?lower_case} docker:build
      mvn -P${pub.getPSSysServiceAPI().getCodeName()?lower_case} docker:push
</#if>     
      docker -H $para1 stack deploy --compose-file=src/main/docker/{{projectName}}-provider-${pub.getPSSysServiceAPI().getCodeName()?lower_case}.yaml ${depplatform.getName()} --with-registry-auth
<#elseif  pub.getPSDeployCenter().getCDType()?? && (pub.getPSDeployCenter().getCDType()=="K8S") >
      cd {{projectName}}-provider
<#if depapi.getUserParam("multiplatform","")?? && depapi.getUserParam("multiplatform","")=="true">   
      mvn -P${pub.getPSSysServiceAPI().getCodeName()?lower_case} exec:exec@prepare
      mvn -P${pub.getPSSysServiceAPI().getCodeName()?lower_case} exec:exec@buildpush      
<#else>   
      mvn -P${pub.getPSSysServiceAPI().getCodeName()?lower_case} docker:build
      mvn -P${pub.getPSSysServiceAPI().getCodeName()?lower_case} docker:push
</#if> 
      set +e
      kubectl --kubeconfig ~/shanghai-demo-01 delete -f src/main/docker/{{projectName}}-provider-${pub.getPSSysServiceAPI().getCodeName()?lower_case}-k8s.yaml -n ${depplatform.getName()?lower_case}
      set -e
      kubectl --kubeconfig ~/shanghai-demo-01 create -f src/main/docker/{{projectName}}-provider-${pub.getPSSysServiceAPI().getCodeName()?lower_case}-k8s.yaml -n ${depplatform.getName()?lower_case}
<#else>
      echo &apos;echo &quot;$para1&quot;&apos; &gt; apppasswd.sh
      chmod -R 777 *
      setsid env SSH_ASKPASS=&apos;./apppasswd.sh&apos; DISPLAY=&apos;none:0&apos; ssh ${depnode.getSSHUserName()}@${depnode.getSSHIPAddr()} &quot;mkdir -p ${depnode.getWorkshopPath()}/${configId}&quot;
      setsid env SSH_ASKPASS=&apos;./apppasswd.sh&apos; DISPLAY=&apos;none:0&apos; scp -r {{projectName}}-provider-${pub.getPSSysServiceAPI().getCodeName()?lower_case}.jar ${depnode.getSSHUserName()}@${depnode.getSSHIPAddr()}:${depnode.getWorkshopPath()}/${configId}
      setsid env SSH_ASKPASS=&apos;./apppasswd.sh&apos; DISPLAY=&apos;none:0&apos; ssh ${depnode.getSSHUserName()}@${depnode.getSSHIPAddr()} &quot;ps -ef | grep &apos;${depnode.getWorkshopPath()}/${configId}&apos;| tr -s &apos; &apos;|cut -d&apos; &apos; -f2,8,9  | grep -v grep | grep &apos;jar&apos; | cut -d&apos; &apos; -f1|xargs  --no-run-if-empty kill -9&quot;
      setsid env SSH_ASKPASS=&apos;./apppasswd.sh&apos; DISPLAY=&apos;none:0&apos; ssh ${depnode.getSSHUserName()}@${depnode.getSSHIPAddr()} &quot;source /etc/profile;source ~/.bash_profile; nohup java -jar -Xms512m -Xmx1024m -XX:PermSize=128M -XX:MaxPermSize=128m ${depnode.getWorkshopPath()}/${configId}/{{projectName}}-provider-${pub.getPSSysServiceAPI().getCodeName()?lower_case}.jar &gt;&gt;${depnode.getWorkshopPath()}/${configId}/${sys.codeName?lower_case}_${config?lower_case}-`date --date=&apos;0 days ago&apos; +%Y-%m-%d`.log 2&gt;&amp;1 &amp;&quot;
</#if>
</#if>
      </command>
    </hudson.tasks.Shell>
  </builders>
  <publishers>
    <hudson.plugins.ws__cleanup.WsCleanup plugin="ws-cleanup@0.34">
      <patterns class="empty-list"/>
      <deleteDirs>false</deleteDirs>
      <skipWhenFailed>false</skipWhenFailed>
      <cleanWhenSuccess>true</cleanWhenSuccess>
      <cleanWhenUnstable>true</cleanWhenUnstable>
      <cleanWhenFailure>true</cleanWhenFailure>
      <cleanWhenNotBuilt>true</cleanWhenNotBuilt>
      <cleanWhenAborted>true</cleanWhenAborted>
      <notFailBuild>false</notFailBuild>
      <cleanupMatrixParent>false</cleanupMatrixParent>
      <externalDelete></externalDelete>
    </hudson.plugins.ws__cleanup.WsCleanup>
  </publishers>
  <buildWrappers/>
</project>
</#if>
</#if>
