Skip to content
Snippets Groups Projects
Jenkinsfile 3.34 KiB
Newer Older
pipeline {
  agent any
  environment {
    GITLAB_API_TOKEN = credentials('GitLabToken')
    COMPOSE_PROJECT_NAME = "${env.JOB_NAME}-${env.BUILD_ID}"
  }
  stages {
    stage('Static Analysis') {
      agent {
        docker { image 'gitlab.rc.uab.edu:4567/center-for-computational-genomics-and-data-science/utility-images/static-analysis:v0.6'}
      }
      steps {
        wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
          sh '/bin/linting.sh'
        }
      }
      post {
        success {
          sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=success&name=jenkins_static_analysis\""
        }
        failure {
          sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=failed&name=jenkins_static_analysis\""
        }
      }
    }
    stage('build') {
      steps {
        sh 'docker-compose -f docker-compose.production.yml build moo-production'
      }
      post {
        success {
          sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=success&name=jenkins_system_tests\""
        }
        failure {
          sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=failed&name=jenkins_system_tests\""
        }
      }
    }
    stage('Publish Updates') {
      when { branch 'master' }
      steps {
        // note -- using `weborg` until we have CGDS @TODO swap out
        sh 'docker login gitlab.rc.uab.edu:4567 -u weborg -p ${GITLAB_API_TOKEN}'
        sh 'docker-compose -f docker-compose.production.yml push'
      }
      post {
        success {
          sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=success&name=updates_published\""
        }
        failure {
          sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=failed&name=updates_published\""
        }
      }
    }
    stage('swarm deploy') {
      when { branch 'master' }
      steps {
        sh 'docker stack deploy --prune --with-registry-auth --compose-file docker-compose.production.yml moo-prod'
      }
      post {
        success {
          sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=success&name=swarm_deployed\""
        }
        failure {
          sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=failed&name=swarm_deployed\""
        }
      }
    }
  }
  post {
    success {
      sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=success&name=jenkins\""
    }
    failure {
      sh "curl --request POST --header \"PRIVATE-TOKEN: ${GITLAB_API_TOKEN}\" \"https://gitlab.rc.uab.edu/api/v4/projects/1014/statuses/${GIT_COMMIT}?state=failed&name=jenkins\""
    }
  }
}