Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
    • Helm Chart
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Spinnaker
    • Jenkins
  • Coding
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Jquery & JavaScript
    • Git
    • Selenium
  • Log & Monitor
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
  • Toggle search form

[jenkins] Scripted Pipeline lesson 3: Stage _ Options

Posted on November 16, 2021 By nim No Comments on [jenkins] Scripted Pipeline lesson 3: Stage _ Options

Contents

  • 1) Error_Retry
    • 1.1) retry into stage
    • 1.2 ) build stage inside a retry block
    • 1.3) node inside a retry block
  • 2) Timeout
    • 2.1) timeout inside stage
    • 2.2 ) build stage inside a retry timeout
    • 2.3 ) node inside a retry timeout
  • 3) Timestamps
    • 3.1) Timestamps for all stage
    • 3.1) Timestamps for particular stage

1) Error_Retry

1.1) retry into stage

node{
    stage('build'){
        retry(3){
            error "Error statement just got executed"
        }
    }
}
khi error thì họ sẽ retry lại

1.2 ) build stage inside a retry block

node{
    retry(3){
        stage('build'){
            error "Error statement just got executed"
        }
    }
}

Ở các hình bên dưới nó sẽ try cả stage luôn nhé

1.3) node inside a retry block

retry(3){
    node{
        error "Error statement just got executed"
    }
}

node được retry 3 lần vì error

2) Timeout

2.1) timeout inside stage

node{
    stage('build'){
        timeout(time: 1, unit: 'SECONDS'){
            // sleeping for 2 seconds
            sleep 2
        }
    }
}
Timeout chỉ cho phép stage đó chạy trong vong 1s là phải xong.
nhưng sleep làm stage trong 2s
vậy thì Aborted pipeline

2.2 ) build stage inside a retry timeout

node{
    timeout(time: 1, unit: 'SECONDS'){
        stage('build'){
            // sleeping for 2 seconds
            sleep 2
        }
    }
}
Timeout xong tiếp theo stage.

2.3 ) node inside a retry timeout

timeout(time: 1, unit: 'SECONDS'){
    node{
        stage('build'){
            // sleeping for 2 seconds
            sleep 2
        }
    }
}

3) Timestamps

https://newbedev.com/jenkins-pipeline-enable-timestamps-in-build-log-console

Như ở link trên thì bạn cần cài thêm plugin mới chạy được.

3.1) Timestamps for all stage

node{
    timestamps{
        stage('build'){
            echo 'Build stage echo statement printed out with timestamp'
        }
        
        stage('deploy'){
            echo 'Deploy stage echo statement printed out with timestamp'
        }
    }
}

3.1) Timestamps for particular stage

node{
    stage('build'){
        timestamps{
            echo 'Build stage echo statement printed out with timestamp'
        }
    }
    
    stage('deploy'){
        echo 'Deploy stage echo statement printed out with timestamp'
    }
}
Mình chỉnh gắn timestamps cho stage build
Jenkins

Post navigation

Previous Post: [Spinnaker] Pipelines of an application hung.
Next Post: [redis-cli] a few Redis commands are useful.

More Related Articles

[Jenkins] Scripted Pipeline lesson 18: Triggers _ PollSCM Jenkins
[Jenkins] Share Libraries 8: Loading Resources Jenkins
[Jenkins] Scripted Pipeline lesson 10: Options _ OverrideIndexTriggers Jenkins
[Jenkins] Lesson 3: Option in Pipeline Jenkins Jenkins
[Jenkins] Scripted Pipeline lesson 14: Options _ NewContainerPerStage. Jenkins
[Jenkins] Lesson 12: skipStagesAfterUnstable with Jenkins Pipeline Jenkins

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Argocd/Vault] Integrate Vault inside Argocd by the plugin July 1, 2022
  • [Vault] Using Service Acount of Kubernetes to login Vault system. June 28, 2022
  • Protected: My Assignment  June 24, 2022
  • [Spinnaker] Spinnaker writes too many logs – Reduce spinnaker log level June 22, 2022
  • [Jenkins] Jobs will be created automatically by Jenkins Job Builder June 20, 2022

Archives

  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Jenkins
    • Spinnaker
  • Coding
    • Git
    • Golang
    • Jquery & JavaScript
    • Laravel
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kubernetes
      • Ingress
    • Longhorn – Storage
    • Vault
    • VictoriaMetrics
  • Log & Monitor
    • ELK
      • Kibana
      • Logstash
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2022 NimTechnology.