Revert "Remove redutant vars/ folder"

This reverts commit a78108cfd53931236d3ee2b32c6e48d4d8eb5c88.

Change-Id: Ibc42fdc12b942b72cb0538cfcef6b933fdaec51a
diff --git a/vars/buildCalicoContainers.groovy b/vars/buildCalicoContainers.groovy
new file mode 100644
index 0000000..1613120
--- /dev/null
+++ b/vars/buildCalicoContainers.groovy
@@ -0,0 +1,93 @@
+def call(body) {
+  // evaluate the body block, and collect configuration into the object
+  def config = [:]
+  body.resolveStrategy = Closure.DELEGATE_FIRST
+  body.delegate = config
+  body()
+
+
+  def dockerRepo = config.dockerRepo
+  def projectNamespace = "mirantis/projectcalico"
+  def artifactoryUrl = config.artifactoryURL
+
+  if (! dockerRepo ) {
+      error('dockerRepo parameter have to be set.')
+  }
+
+  if (! artifactoryUrl ) {
+      error('artifactoryUrl parameter have to be set.')
+  }
+
+  def git = new com.mirantis.mcp.Git()
+  def common = new com.mirantis.mcp.Common()
+  def imgTag = config.imageTag ?: git.getGitDescribe(true) + "-" + common.getDatetime()
+
+  def nodeImage = config.nodeImage ?: "${dockerRepo}/${projectNamespace}/calico/node"
+  def nodeName = "${nodeImage}:${imgTag}"
+
+  def ctlImage = config.ctlImage ?: "${dockerRepo}/${projectNamespace}/calico/ctl"
+  def ctlName = "${ctlImage}:${imgTag}"
+
+   // calico/build goes from libcalico
+  def buildImage = config.buildImage ?: "${dockerRepo}/${projectNamespace}/calico/build:latest"
+  // calico/felix goes from felix
+  def felixImage = config.felixImage ?: "${dockerRepo}/${projectNamespace}/calico/felix:latest"
+
+  def confdBuildId = config.confdBuildId ?: "${artifactoryUrl}/${projectNamespace}/confd/latest".toURL().text.trim()
+  def confdUrl = config.confdUrl ?: "${artifactoryUrl}/${projectNamespace}/confd/confd-${confdBuildId}"
+
+  def birdBuildId = config.birdBuildId ?: "${artifactoryUrl}/${projectNamespace}/bird/latest".toURL().text.trim()
+  def birdUrl = config.birdUrl ?: "${artifactoryUrl}/${projectNamespace}/bird/bird-${birdBuildId}"
+  def bird6Url = config.bird6Url ?: "${artifactoryUrl}/${projectNamespace}/bird/bird6-${birdBuildId}"
+  def birdclUrl = config.birdclUrl ?: "${artifactoryUrl}/${projectNamespace}/bird/birdcl-${birdBuildId}"
+
+  // add LABELs to dockerfiles
+  def docker = new com.mirantis.mcp.Docker()
+  docker.setDockerfileLabels("./calicoctl/Dockerfile.calicoctl",
+                            ["docker.imgTag=${imgTag}",
+                             "calico.buildImage=${buildImage}",
+                             "calico.birdclUrl=${birdclUrl}"])
+
+  docker.setDockerfileLabels("./calico_node/Dockerfile",
+                            ["docker.imgTag=${imgTag}",
+                             "calico.buildImage=${buildImage}",
+                             "calico.felixImage=${felixImage}",
+                             "calico.confdUrl=${confdUrl}",
+                             "calico.birdUrl=${birdUrl}",
+                             "calico.bird6Url=${bird6Url}",
+                             "calico.birdclUrl=${birdclUrl}"])
+
+  // Start build section
+  stage ('Build calico/ctl image'){
+    sh """
+      make calico/ctl \
+        CTL_CONTAINER_NAME=${ctlName} \
+        PYTHON_BUILD_CONTAINER_NAME=${buildImage} \
+        BIRDCL_URL=${birdclUrl}
+    """
+  }
+
+
+  stage('Build calico/node'){
+    sh """
+      make calico/node \
+        NODE_CONTAINER_NAME=${nodeName} \
+        PYTHON_BUILD_CONTAINER_NAME=${buildImage} \
+        FELIX_CONTAINER_NAME=${felixImage} \
+        CONFD_URL=${confdUrl} \
+        BIRD_URL=${birdUrl} \
+        BIRD6_URL=${bird6Url} \
+        BIRDCL_URL=${birdclUrl}
+    """
+  }
+
+
+  return [
+    CTL_CONTAINER_NAME:"${ctlName}",
+    NODE_CONTAINER_NAME:"${nodeName}",
+    CALICO_NODE_IMAGE_REPO:"${nodeImage}",
+    CALICOCTL_IMAGE_REPO:"${ctlImage}",
+    CALICO_VERSION: "${imgTag}"
+  ]
+
+}
diff --git a/vars/buildCalicoContainers.txt b/vars/buildCalicoContainers.txt
new file mode 100644
index 0000000..ce54270
--- /dev/null
+++ b/vars/buildCalicoContainers.txt
@@ -0,0 +1,30 @@
+// Usage example
+// List of parameters with the default values
+  def dockerRepo = config.dockerRepo ?: "mcp-k8s-ci.docker.mirantis.net"
+  def artifactoryUrl = config.artifactoryURL ?: "https://artifactory.mcp.mirantis.net/artifactory/projectcalico"
+  def nodeImage = config.nodeImage ?: "calico/node"
+  def nodeImageTag = config.nodeImageTag ?: "v1.0.0-beta"
+  def ctlImage = config.ctlImage ?: "calico/ctl"
+  def ctlImageTag = config.ctlImageTag ?: "v1.0.0-beta"
+  def buildImage = config.buildImage ?: "${artifactoryURL}/mcp/libcalico/lastbuild".toURL().text.trim()
+  def felixImage = config.felixImage ?: "${artifactoryURL}/mcp/felix/lastbuild".toURL().text.trim()
+  def confdBuildId = config.confdBuildId ?: "${artifactoryURL}/mcp/confd/lastbuild".toURL().text.trim()
+  def confdUrl = config.confdUrl ?: "${artifactoryURL}/mcp/confd/confd-${confdBuildId}"
+  def birdBuildId = config.birdBuildId ?: "${artifactoryURL}/mcp/calico-bird/lastbuild".toURL().text.trim()
+  def birdUrl = config.birdUrl ?: "${artifactoryURL}/mcp/calico-bird/bird-${birdBuildId}"
+  def bird6Url = config.bird6Url ?: "${artifactoryURL}/mcp/calico-bird/bird6-${birdBuildId}"
+  def birdclUrl = config.birdclUrl ?: "${artifactoryURL}/mcp/calico-bird/birdcl-${birdBuildId}"
+  def build = "${config.containersBuildId}-${gitCommit}"
+
+// *** Examples 1:
+// we still use old schema and want to publish to GERRIT_CHANGE_NUMBER
+def buildId = ${GERRIT_CHANGE_NUMBER}
+// we want to store in artifacts from gate then
+def buildId = "mcp"
+node {
+    buildCalicoContainers {
+      dockerRepo = "mcp-k8s-ci.docker.mirantis.net"
+      artifactoryURL = "https://artifactory.mcp.mirantis.net/artifactory/sandbox"
+      containersBuildId = buildId
+    }
+}
diff --git a/vars/gerritPatchsetCheckout.groovy b/vars/gerritPatchsetCheckout.groovy
new file mode 100644
index 0000000..a3fd1f5
--- /dev/null
+++ b/vars/gerritPatchsetCheckout.groovy
@@ -0,0 +1,39 @@
+def call(body) {
+  // evaluate the body block, and collect configuration into the object
+  def config = [:]
+  body.resolveStrategy = Closure.DELEGATE_FIRST
+  body.delegate = config
+  body()
+
+
+  def merge = config.withMerge ?: false
+  def wipe = config.withWipeOut ?: false
+
+  // default parameters
+  def scmExtensions = [
+    [$class: 'CleanCheckout'],
+    [$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']]
+  ]
+  // if we need to "merge" code from patchset to GERRIT_BRANCH branch
+  if (merge) {
+    scmExtensions.add([$class: 'LocalBranch', localBranch: "${GERRIT_BRANCH}"])
+  }
+  // we need wipe workspace before checkout
+  if (wipe) {
+    scmExtensions.add([$class: 'WipeWorkspace'])
+  }
+
+  checkout(
+    scm: [
+      $class: 'GitSCM',
+      branches: [[name: "${GERRIT_BRANCH}"]],
+      extensions: scmExtensions,
+      userRemoteConfigs: [[
+        credentialsId: "${config.credentialsId}",
+        name: 'gerrit',
+        url: "ssh://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}.git",
+        refspec: "${GERRIT_REFSPEC}"
+      ]]
+    ]
+  )
+}
diff --git a/vars/gerritPatchsetCheckout.txt b/vars/gerritPatchsetCheckout.txt
new file mode 100644
index 0000000..2372bf6
--- /dev/null
+++ b/vars/gerritPatchsetCheckout.txt
@@ -0,0 +1,22 @@
+// Usage example
+node {
+  gerritPatchsetCheckout{
+    credentialsId = "credentials-id-string"
+  }
+}
+
+// Usage example with merging to checkouted branch
+node {
+  gerritPatchsetCheckout{
+    credentialsId = "credentials-id-string"
+    withMerge = true
+  }
+}
+
+// wipe our repository and force clone
+node {
+  gerritPatchsetCheckout{
+    credentialsId = "credentials-id-string"
+    withWipeOut = true
+  }
+}
diff --git a/vars/gitSSHCheckout.groovy b/vars/gitSSHCheckout.groovy
new file mode 100644
index 0000000..cf6e0e4
--- /dev/null
+++ b/vars/gitSSHCheckout.groovy
@@ -0,0 +1,40 @@
+def call(body) {
+  // evaluate the body block, and collect configuration into the object
+  def config = [:]
+  body.resolveStrategy = Closure.DELEGATE_FIRST
+  body.delegate = config
+  body()
+
+  def merge = config.withMerge ?: false
+  def wipe = config.withWipeOut ?: false
+  def targetDir = config.targetDir ?: "./"
+  def port = config.port ?: "29418"
+
+  // default parameters
+  def scmExtensions = [
+    [$class: 'CleanCheckout'],
+    [$class: 'RelativeTargetDirectory', relativeTargetDir: "${targetDir}"]
+  ]
+
+  // https://issues.jenkins-ci.org/browse/JENKINS-6856
+  if (merge) {
+    scmExtensions.add([$class: 'LocalBranch', localBranch: "${config.branch}"])
+  }
+  // we need wipe workspace before checkout
+  if (wipe) {
+    scmExtensions.add([$class: 'WipeWorkspace'])
+  }
+
+  checkout(
+    scm: [
+      $class: 'GitSCM',
+      branches: [[name: "${config.branch}"]],
+      extensions: scmExtensions,
+      userRemoteConfigs: [[
+        credentialsId: "${config.credentialsId}",
+        name: 'origin',
+        url: "ssh://${config.credentialsId}@${config.host}:${port}/${config.project}.git"
+      ]]
+    ]
+  )
+}
diff --git a/vars/gitSSHCheckout.txt b/vars/gitSSHCheckout.txt
new file mode 100644
index 0000000..b01939e
--- /dev/null
+++ b/vars/gitSSHCheckout.txt
@@ -0,0 +1,70 @@
+// Default parameters
+
+  targetDir = "./"
+  port = "29418"
+
+// Usage example
+node {
+  gitSSHCheckout {
+    credentialsId = "mcp-ci-gerrit"
+    branch = "mcp-0.1"
+    host = "ci.mcp-ci.local"
+    project = "projectcalico/calico-containers"
+  }
+}
+
+// or
+
+node {
+  gitSSHCheckout {
+    credentialsId = "mcp-ci-gerrit"
+    branch = "mcp-0.1"
+    host = "ci.mcp-ci.local"
+    project = "projectcalico/calico-containers"
+    targetDir = "some_directory"
+  }
+}
+
+// by default if you checkout even to branch you will be in detached mode
+// but some tools (e.g. pip) requires "merged" code
+// https://issues.jenkins-ci.org/browse/JENKINS-6856
+// so you need to use withMerge = true
+
+node {
+  gitSSHCheckout {
+    credentialsId = "mcp-ci-gerrit"
+    branch = "mcp"
+    host = "ci.mcp-ci.local"
+    project = "projectcalico/calico-containers"
+    targetDir = "some_directory"
+    withMerge = true
+  }
+}
+
+Please see example below:
+1. withMerge = false (default)
+  $ git status
+  HEAD detached at 25fd9c2
+  nothing to commit, working directory clean
+  $ git branch -av
+  * (HEAD detached at 25fd9c2)       25fd9c2 Fix .gitreview
+    remotes/origin/HEAD              7e2b36e Merge pull request #160 from tomdee/tiny-build-image-size-tweaks
+    remotes/origin/develop           013614f Merge pull request #144 from djosborne/comment-etcd-pin
+    remotes/origin/feature/utreports 3c52c2a disable usage reports while running unit tests
+    remotes/origin/go                350e251 Merge pull request #128 from caseydavenport/ipam-code-review
+    remotes/origin/master            7e2b36e Merge pull request #160 from tomdee/tiny-build-image-size-tweaks
+    remotes/origin/mcp               25fd9c2 Fix .gitreview
+
+
+2. withMerge = true
+  $ git status
+  On branch mcp
+  nothing to commit, working directory clean
+  $ git branch -av
+  * mcp                              25fd9c2 Fix .gitreview
+    remotes/origin/HEAD              7e2b36e Merge pull request #160 from tomdee/tiny-build-image-size-tweaks
+    remotes/origin/develop           013614f Merge pull request #144 from djosborne/comment-etcd-pin
+    remotes/origin/feature/utreports 3c52c2a disable usage reports while running unit tests
+    remotes/origin/go                350e251 Merge pull request #128 from caseydavenport/ipam-code-review
+    remotes/origin/master            7e2b36e Merge pull request #160 from tomdee/tiny-build-image-size-tweaks
+    remotes/origin/mcp               25fd9c2 Fix .gitreview
diff --git a/vars/runTox.groovy b/vars/runTox.groovy
new file mode 100644
index 0000000..8b3f97c
--- /dev/null
+++ b/vars/runTox.groovy
@@ -0,0 +1,8 @@
+def call(String env=null) {
+  // Run tox with or without specified environment
+  if (env==null) {
+    sh "tox -v"
+  } else {
+    sh "tox -v -e ${env}"
+  }
+}