<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description>Builds and deploys version of frontend-@APP_NAME@ bundle to CDN.</description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <hudson.plugins.buildblocker.BuildBlockerProperty plugin="build-blocker-plugin">
      <useBuildBlocker>false</useBuildBlocker>
      <blockLevel>GLOBAL</blockLevel>
      <scanQueueFor>DISABLED</scanQueueFor>
      <blockingJobs></blockingJobs>
    </hudson.plugins.buildblocker.BuildBlockerProperty>
    <org.datadog.jenkins.plugins.datadog.DatadogJobProperty plugin="datadog">
      <emitOnCheckout>false</emitOnCheckout>
      <tagProperties>environment=${ENV}
deploy=frontend-@APP_NAME
app=frontend
commit=${GIT_COMMIT}
      </tagProperties>
    </org.datadog.jenkins.plugins.datadog.DatadogJobProperty>
    <com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty plugin="build-failure-analyzer">
      <doNotScan>false</doNotScan>
    </com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty>
    <com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty plugin="naginator">
      <optOut>false</optOut>
    </com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty>
    <hudson.model.ParametersDefinitionProperty>
      <parameterDefinitions>
        <hudson.model.ChoiceParameterDefinition>
          <name>ENV</name>
          <description>CDN environment to deploy to.</description>
          <choices class="java.util.Arrays$ArrayList">
            <a class="string-array">
              <string>qa</string>
              <string>prod</string>
            </a>
          </choices>
        </hudson.model.ChoiceParameterDefinition>
        <hudson.model.StringParameterDefinition>
          <name>GIT_COMMIT</name>
          <description>Commit version to checkout and build bundle to.</description>
          <defaultValue></defaultValue>
        </hudson.model.StringParameterDefinition>
        <hudson.model.StringParameterDefinition>
          <name>S3_PATH</name>
          <description/>
          <defaultValue>${ENV}-orcd-cdn/frontend-@APP_NAME@</defaultValue>
        </hudson.model.StringParameterDefinition>
        <hudson.model.StringParameterDefinition>
          <name>POEDITOR_PROJECT_ID</name>
          <description>Identifier for POEditor Project</description>
          <defaultValue>@POEDITOR_PROJECT_ID@</defaultValue>
        </hudson.model.StringParameterDefinition>
        <hudson.model.PasswordParameterDefinition>
          <name>API_KEY</name>
          <description>API Key for POEditor Project</description>
          <defaultValue>@POEDITOR_API_KEY@</defaultValue>
        </hudson.model.PasswordParameterDefinition>
        <hudson.model.ChoiceParameterDefinition>
          <name>MINIFY</name>
          <description>Indicates whether to minify the bundle</description>
          <choices class="java.util.Arrays$ArrayList">
            <a class="string-array">
              <string>0</string>
              <string>1</string>
            </a>
          </choices>
        </hudson.model.ChoiceParameterDefinition>
        <hudson.model.StringParameterDefinition>
          <name>USER_ID</name>
          <description>User ID used to obtain grass session token to power the standalone environment.</description>
          <defaultValue>@USER_ID@</defaultValue>
        </hudson.model.StringParameterDefinition>
      </parameterDefinitions>
    </hudson.model.ParametersDefinitionProperty>
    <hudson.plugins.throttleconcurrents.ThrottleJobProperty plugin="throttle-concurrents">
      <maxConcurrentPerNode>0</maxConcurrentPerNode>
      <maxConcurrentTotal>0</maxConcurrentTotal>
      <categories class="java.util.concurrent.CopyOnWriteArrayList"/>
      <throttleEnabled>false</throttleEnabled>
      <throttleOption>project</throttleOption>
      <limitOneJobWithMatchingParams>false</limitOneJobWithMatchingParams>
      <paramsToUseForLimit></paramsToUseForLimit>
    </hudson.plugins.throttleconcurrents.ThrottleJobProperty>
  </properties>
  <scm class="hudson.plugins.git.GitSCM" plugin="git">
    <configVersion>2</configVersion>
    <userRemoteConfigs>
      <hudson.plugins.git.UserRemoteConfig>
        <url>git@github.com:theorchard/frontend-@APP_NAME@.git</url>
        <credentialsId>@GITHUB_CREDENTIAL_ID@</credentialsId>
      </hudson.plugins.git.UserRemoteConfig>
    </userRemoteConfigs>
    <branches>
      <hudson.plugins.git.BranchSpec>
        <name>${GIT_COMMIT}</name>
      </hudson.plugins.git.BranchSpec>
    </branches>
    <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
    <submoduleCfg class="list"/>
    <extensions>
      <hudson.plugins.git.extensions.impl.AuthorInChangelog/>
    </extensions>
  </scm>
  <assignedNode>@ALLOWED_NODE@</assignedNode> 
  <canRoam>false</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers/>
  <concurrentBuild>false</concurrentBuild>
  <builders>
    <hudson.tasks.Shell>
      <command># sets up grass token - using @USER_ID@

rm -fR venv

# create the environment
pyvenv-3.6 venv
source venv/bin/activate

pip install -i https://pypi.theorchard.io/pypi/ qa-utils-grass==$UTILS_GRASS_VERSION

echo &quot;GRASS_TOKEN=`python - &lt;&lt;EOF
from auth.auth import GrassAuth, UserType
workstation_token = GrassAuth(UserType.WORKSTATION, $USER_ID).grass_token
print(workstation_token)
EOF`&quot; &gt; grasstoken.properties</command>
    </hudson.tasks.Shell>
    <EnvInjectBuilder plugin="envinject">
      <info>
        <propertiesFilePath>grasstoken.properties</propertiesFilePath>
      </info>
    </EnvInjectBuilder>
    <hudson.tasks.Shell>
      <command>#!/bin/sh -ex
echo $GIT_COMMIT
export DEPLOY_TIMESTAMP=${GIT_COMMIT}
export TIMESTAMP=${GIT_COMMIT}

jobStartTime=$(date +%s)
echo $(date -d @$jobStartTime +&quot;Job started at: %Y-%m-%d %H:%M:%S&quot;)

if [ &quot;$ENV&quot; = &quot;prod&quot; ]; then
	export GRASS_TOKEN=&apos;&apos;
  export CDN_URL=https://cdn.theorchard.io
  # Copy bundled content from QA CDN
  aws s3 cp s3://qa-orcd-cdn/frontend-@APP_NAME@/manifest.json build/manifest.json
  aws s3 cp s3://qa-orcd-cdn/frontend-@APP_NAME@/${GIT_COMMIT}/ build/${GIT_COMMIT}/. --recursive
elif [ &quot;$ENV&quot; = &quot;qa&quot; ]; then
    export CDN_URL=https://qa-cdn.theorchard.io
    # Check yarn version and run. 
    node --version
    yarn --version
    yarn --frozen-lockfile
    yarn deploy
fi

cat build/manifest.json
echo $CDN_URL
jobEndTime=$(date +%s)
echo $(date -d @$jobEndTime +&quot;Job finished at: %Y-%m-%d %H:%M:%S&quot;)
elapsedSeconds=$(($jobEndTime - $jobStartTime))
printf &quot;Job duration: %d minutes %d seconds\n&quot; $(($elapsedSeconds/60)) $(($elapsedSeconds%60))</command>
    </hudson.tasks.Shell>
  </builders>
  <publishers>
    <hudson.plugins.s3.S3BucketPublisher plugin="s3">
      <profileName>@CDN_DEPLOY_PROFILE@</profileName>
      <entries>
        <hudson.plugins.s3.Entry>
          <bucket>${S3_PATH}/${GIT_COMMIT}</bucket>
          <sourceFile>build/</sourceFile>
          <excludedFile>build/manifest.json</excludedFile>
          <storageClass>STANDARD</storageClass>
          <selectedRegion>us-east-1</selectedRegion>
          <noUploadOnFailure>true</noUploadOnFailure>
          <uploadFromSlave>false</uploadFromSlave>
          <managedArtifacts>false</managedArtifacts>
          <useServerSideEncryption>false</useServerSideEncryption>
          <flatten>true</flatten>
          <gzipFiles>false</gzipFiles>
        </hudson.plugins.s3.Entry>
        <hudson.plugins.s3.Entry>
          <bucket>${S3_PATH}</bucket>
          <sourceFile>build/*.*</sourceFile>
          <excludedFile></excludedFile>
          <storageClass>STANDARD</storageClass>
          <selectedRegion>us-east-1</selectedRegion>
          <noUploadOnFailure>true</noUploadOnFailure>
          <uploadFromSlave>false</uploadFromSlave>
          <managedArtifacts>false</managedArtifacts>
          <useServerSideEncryption>false</useServerSideEncryption>
          <flatten>true</flatten>
          <gzipFiles>false</gzipFiles>
        </hudson.plugins.s3.Entry>
      </entries>
      <dontWaitForConcurrentBuildCompletion>false</dontWaitForConcurrentBuildCompletion>
      <userMetadata/>
    </hudson.plugins.s3.S3BucketPublisher>
    <jenkins.plugins.slack.SlackNotifier plugin="slack">
      <baseUrl></baseUrl>
      <teamDomain>orcd</teamDomain>
      <authToken></authToken>
      <authTokenCredentialId>@SLACK_CREDENTIAL_ID@</authTokenCredentialId>
      <botUser>false</botUser>
      <room>@SLACK_ROOMS@</room>
      <startNotification>false</startNotification>
      <notifySuccess>false</notifySuccess>
      <notifyAborted>false</notifyAborted>
      <notifyNotBuilt>true</notifyNotBuilt>
      <notifyUnstable>true</notifyUnstable>
      <notifyRegression>false</notifyRegression>
      <notifyFailure>true</notifyFailure>
      <notifyBackToNormal>true</notifyBackToNormal>
      <notifyRepeatedFailure>false</notifyRepeatedFailure>
      <includeTestSummary>false</includeTestSummary>
      <includeFailedTests>false</includeFailedTests>
      <commitInfoChoice>AUTHORS_AND_TITLES</commitInfoChoice>
      <includeCustomMessage>false</includeCustomMessage>
      <customMessage>Commit Sha $GIT_COMMIT deployed</customMessage>
    </jenkins.plugins.slack.SlackNotifier>
  </publishers>
  <buildWrappers>
    <hudson.plugins.ws__cleanup.PreBuildCleanup plugin="ws-cleanup">
      <deleteDirs>false</deleteDirs>
      <cleanupParameter></cleanupParameter>
      <externalDelete></externalDelete>
    </hudson.plugins.ws__cleanup.PreBuildCleanup>
    <hudson.plugins.timestamper.TimestamperBuildWrapper plugin="timestamper"/>
    <hudson.plugins.ansicolor.AnsiColorBuildWrapper plugin="ansicolor">
      <colorMapName>xterm</colorMapName>
    </hudson.plugins.ansicolor.AnsiColorBuildWrapper>
    <EnvInjectBuildWrapper plugin="envinject">
      <info>
        <propertiesContent>QA_DB_DATABASE=art_relations
QA_DB_HOST=qa.db.qaorch.com
QA_DB_USER=automation_qa
QA_GRASS_HOST=https://api-dev.theorchard.io/auth/session
UTILS_GRASS_VERSION=0.4.0
      </propertiesContent>
        <secureGroovyScript plugin="script-security">
          <script></script>
          <sandbox>true</sandbox>
        </secureGroovyScript>
        <loadFilesFromMaster>false</loadFilesFromMaster>
      </info>
    </EnvInjectBuildWrapper>
    <EnvInjectPasswordWrapper plugin="envinject">
      <injectGlobalPasswords>false</injectGlobalPasswords>
      <maskPasswordParameters>true</maskPasswordParameters>
      <passwordEntries>
        <EnvInjectPasswordEntry>
          <name>QA_DB_PASS</name>
          <value>@QA_DB_PASS@</value>
        </EnvInjectPasswordEntry>
      </passwordEntries>
    </EnvInjectPasswordWrapper>
    <jenkins.plugins.nodejs.tools.NpmPackagesBuildWrapper plugin="nodejs">
    <nodeJSInstallationName>nodejs @NODE_VERSION@</nodeJSInstallationName>
    </jenkins.plugins.nodejs.tools.NpmPackagesBuildWrapper>
  </buildWrappers>
</project>
