pipeline {
  agent {
    label "swarm"
  }
  environment {
    git_url=""
    docker_registry='dev-registry.infoclinica.ru:5000'
    docker_image='node'
  }
  parameters {
    string(
      name: "build",
      defaultValue: "true",
      description: "To build image set built to 'true'. To not build, set parameter to anything else - 'false'."
    )
    string(
      name: "repo",
      defaultValue: "prod",
      description: "Repository to build and/or deploy from."
    )
    string(
      name: "service_update",
      defaultValue: "",
      description: "Services to update - i.e. info_node or/and info_node-api. Lave empty to not update services."
    )
  }
  stages {
    stage("Build") {
      when { expression { build == "true" } }
      steps {
        echo "Building with repo $repo"
        sh "echo docker build -t ${docker_registry}/${docker_image}:${repo}-${BUILD_NUMBER} ${WORKSPACE}"
      }
    }
    stage("Update") {
      when { expression { service_update != "" } }
      steps {
        echo "Updating .$service_update."
        script {
          for (String item : service_update.split()) {
            echo "Updating $item"
          }
        }
        sh 'ls'
      }
    }
  }
  post {
    always {
      echo "It's always good to be here."
    }
    changed {
      echo "Something changed..."
    }
    failure {
      echo "Oh, snap. It's failed again"
    }
    success {
      echo "Fine !!! It's SUCCESS !!!"
    }
    unstable {
      echo "Unstable ...."
    }
    aborted {
      echo "Hmmm... It's aborted"
    }
  }
}