@Library('jenkins-pipeline-library') import com.gentics.*
JobContext.set(this)



pipeline {
	agent {
		kubernetes {
			label env.BUILD_TAG
			defaultContainer 'build'
			yaml """
apiVersion: v1
kind: Pod
spec:
  volumes:
  - name: cache
    hostPath:
      path: /opt/kubernetes/cache

  containers:
  - name: build
    image: """ + buildEnvironmentDockerImage("ci/Dockerfile.build") + """
    imagePullPolicy: Always
    command:
    - cat
    tty: true
    resources:
      requests:
        cpu: 2
        memory: 1Gi
    volumeMounts:
    - mountPath: /home/jenkins/.composer/cache
      name: cache
      subPath: composer/cache
  imagePullSecrets:
  - name: docker-jenkinsbuilds-apa-it
"""
		}
	}

	options {
		timestamps()
		timeout(time: 1, unit: 'HOURS')
		ansiColor('xterm')
	}

	triggers {
		githubPush()
	}

	stages {
		stage("Build") {
			steps {
				githubBuildStarted()

				sh "composer build"
			}

			post {
				always {
					junit  ".reports/*.xml"
				}
			}
		}
	}

	post {
		always {
			githubBuildEnded()
			notifyMattermostUsers()
		}
	}
}
