package com.abnamro.flow

/**
 * This is an example flow for a npm/gulp application which has a static website as output.
 * These properties have to be here, they actually get saved after the first execection.
 * And they become normal Jenkins Job Parameters. Which is why we use "hidden", as we don't actually want to adjust them during a manual build.
 */

// Assert all required values for the flow
assert "$env.flowType" != null
assert "$env.branchType" != null
assert "$env.semVer" != null
assert "$env.componentScm" != null
assert "$env.componentBranch" != null
assert "$env.componentCredentialsId" != null
assert "$env.versionJob" != null
assert "$env.deployJob" != null


def runFlow() {
    stage 'Executing Workflow'
    def steps
    node {
        pwd()
        unstash 'flowFiles'
        steps = load 'src\\main\\groovy\\com\\abnamro\\flow\\common\\Steps.groovy'
    }

    echo "BRANCH_NAME=$env.BRANCH_NAME"
    echo "push_commit=$push_commit"
    echo "flowType=$flowType"
    echo "sourceBranch=$sourceBranch"
    echo "sourceCommitHash=$sourceCommitHash"
    echo "targetBranch=$targetBranch"

    steps.determineGitFlowBranchType(env.BRANCH_NAME)

    steps.checkoutGitComponent()

    // Execute the required steps
    checkpoint "_Branch: $env.BRANCH_NAME"
    if ("$env.branchType" == "stable") {
        steps.updateBuildDescription("$flowType")
    } else {
        steps.updateBuildDescription("$env.BRANCH_NAME - $flowType")
    }
    steps.npmBuild()
    checkpoint 'Build & Test Completed'

    if ("$flowType" == "nightly" || "$flowType" == "release") {
        steps.versionStage()
        steps.publishStage()
    }
    checkpoint 'Version released in Nexus'

    if ("$flowType" == "release") {
        steps.retrieveArtifactFromNexusStage()
        steps.publishDocumentationStage()
    }

    steps.stashSuccessNotification()
}
return this;
