Knowledge base
  • Goal of knowledge base
  • Linux & core
    • Linux
      • Record SSH session for reporting
      • Compress / Decompress files
      • Colorize logs
      • Cron output & logging
      • Signal
      • Break out and escape SSH session
      • Mount volume permanently
      • Show processes most consuming CPU & MEM
      • Improve and optimize battery life on Linux
      • File ownership & groups in linux
      • Automatic security update/patch on Ubuntu
      • Clean buffers and cached on linux
      • Bash completion on Linux/Mac
    • Core services
      • Nginx reload
      • OpenVPN Split tunneling
      • Nmap commands
    • Hardware
      • CPU Architecture fundamental
  • Database
    • MySQL
      • InnoDB - innodb_file_per_table parameter
      • MySQL - enable slow query log
      • MySQL - export large tables
    • MongoDB
  • Container
    • Docker
      • ADD or COPY in Dockerfile
        • Clean data of docker completely
    • Podman
  • Automation
    • Ansible
      • Output format
  • Build & Deployment
    • Jenkins
      • Jenkins - force exit pipeline when failure
  • Language & Toolset
    • PHP
      • Composer
      • php-redis & php-igbinary
  • Mindset
    • Technical based
      • Writing well
      • Reinvent The Wheel
      • Approach a new system
      • Backup philosophy
      • Mindset for building HA and scalable system
      • GitLab database incident
    • Non-technical based
      • How to read news efficiency?
      • How long should you nap?
      • Assume good faith
  • Reference & learning source
    • Books
      • Sysadmin/SRE
      • Mindsets
      • Software fundamentals
    • English
Powered by GitBook
On this page
  • 1. Issue
  • 2. Solution
  1. Build & Deployment
  2. Jenkins

Jenkins - force exit pipeline when failure

1. Issue

In some specific cases, if we use try catch exception, Jenkins knows that issues, but still continue running other stage in pipeline. We need a force handling to make this pipeline failure immediately

2. Solution

currentBuild.result = 'FAILURE'
error("Failure right here, force exit")
stage("DB migration") {
  steps { script {
    slackSend (color: COLOR_MAP['SUCCESS'],
               channel: '#live-deployment',
               token: 'Fawxxxxxxxxxxxx',
               message: "*`STARTING`*: *core db migrating*, build #${env.BUILD_NUMBER}, <${env.BUILD_URL}|Go to this job>")
    try {
      withCredentials([usernamePassword(credentialsId: 'xxxxx-credential', usernameVariable: 'DB_USERNAME', passwordVariable: 'DB_PASSWORD')]) {
        withAWS(region:"eu-cexxxxxxx", credentials:"aws") {
          sh """
            packer build -force dbmigration/vm-db-migration.json
          """
        }
      }
    } catch (error) {
        slackSend (color: COLOR_MAP['FAILURE'],
                   channel: '#live-deployment',
                   token: 'Fawxxxxxxxxxxxx',
                   message: "*`FAILURE`*: *core db migrating*, build #${env.BUILD_NUMBER} \n${error}\n<${env.BUILD_URL}|Go to this job>")
        currentBuild.result = 'FAILURE'
        error("${error}")
    }
  }}
}
PreviousJenkinsNextPHP

Last updated 6 years ago