node {
    cleanWs()
}
node {
    stage('checkout') {
        checkout ([ \
            $class: 'GitSCM', \
            branches: [[name: '*/master']], \
            doGenerateSubmoduleConfigurations: false, \
            extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'devops'], [ $class: 'ScmName', name: 'devops' ]], \
            submoduleCfg: [], \
            userRemoteConfigs: [[credentialsId: '9af2bd5f-a2b4-4470-8356-64e9a5576c0a', url: 'git@github.com:BigscreenVR/devops.git']] \
        ])
        checkout ([ \
            $class: 'GitSCM', \
            branches: [[name: '*/main-rice']], \
            doGenerateSubmoduleConfigurations: false, \
            extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'cloud'], [ $class: 'ScmName', name: 'cloud' ]], \
            submoduleCfg: [], \
            userRemoteConfigs: [[credentialsId: '52e464f0-e4bd-4adb-9438-a10ffffae1e1', url: 'git@github.com:BigscreenVR/cloud.git']] \
        ])
    }
}
node {
    try {
        stage("build_webapp_arda") {
            sh '''#!/bin/bash
. `pwd`/devops/Jenkins/server_builder_v7.sh
NETWORK="main"
FLEET="rice"
build_webapp_arda $NETWORK $FLEET
'''
        }
        stage("post_build") {
            sh '''#!/bin/bash
NETWORK="main"
FLEET="rice"
MESSAGE=":rice::rice::rice: **[$NETWORK-$FLEET] Web apps** :mage::mage::mage: :rice::rice::rice:"
bash `pwd`/devops/Jenkins/deps/discord.sh \
    --webhook-url="https://discordapp.com/api/webhooks/516791347613532207/YVB-QQcWfwzN5sDunKgNuSmWl3KI1aAEi_QMiX93BMDdTtOmrCxQaiqKGdOHj85g_Yfv" \
    --username "Jenkins" \
    --avatar "https://icon-library.com/images/jenkins-icon/jenkins-icon-15.jpg" \
    --title "$MESSAGE" \
    --color "3066993" \
    --url "$JOB_URL" \
    --description ":mage::mage::mage: WebApps: Arda, Fabricator, Rohan, Website" \
    --field "Network;$NETWORK;true" \
    --field "Fleet;$FLEET;true" \
    --field "Branch;$NETWORK-$FLEET;true" \
    --field "Arda;https://$NETWORK-$FLEET-arda.bigscreencloud.com;false" \
    --field "Rohan;https://$NETWORK-$FLEET-rohan.bigscreencloud.com;false" \
    --field "Changes;TODO: list changes here.;false" \
    --timestamp 
'''
        }
    } catch (e) {
        sh '''#!/bin/bash
NETWORK="main"
FLEET="rice"
MESSAGE=":x::x::x: **BUILD FAILED [$NETWORK-$FLEET] Web Apps!!!** :x::x::x:"
bash `pwd`/devops/Jenkins/deps/discord.sh \
    --webhook-url="https://discordapp.com/api/webhooks/516791347613532207/YVB-QQcWfwzN5sDunKgNuSmWl3KI1aAEi_QMiX93BMDdTtOmrCxQaiqKGdOHj85g_Yfv" \
    --username "Jenkins" \
    --avatar "https://icon-library.com/images/jenkins-icon/jenkins-icon-15.jpg" \
    --title "$MESSAGE" \
    --color "15548997" \
    --url "$JOB_URL" \
    --timestamp 
'''
        throw e
    }
}