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] Lesson 3: Option in Pipeline Jenkins

Posted on October 29, 2021October 30, 2021 By nim No Comments on [Jenkins] Lesson 3: Option in Pipeline Jenkins

Contents

  • Option in Pipeline Scipt
    • option – retry – steps – error
    • option – retry – not work with currentBuild.result = “FAILURE”
    • option – timeout – steps – sleep
    • option – timestamp() – Invalid option type “timestamps”
      • Invalid
      • resolve above problem
    • options-skipdefaultcheckout
      • skip default checkout
      • don’t skip default checkout
        • Agent of agent

Option in Pipeline Scipt

https://www.jenkins.io/doc/book/pipeline/syntax/#options

option – retry – steps – error

pipeline{
    agent any
    stages{
        stage("Build"){
            options{
                retry(3)
            }
            steps{
                echo "before error statement"
                error "Error statement just get executed"
                echo "after error statement"
            }
        }
    }
}
Đây là output

option – retry – not work with currentBuild.result = “FAILURE”

pipeline{
    agent any
    stages{
        steps("Build"){
            options{
                retry(3)
            }
            steps{
                echo "before setting current build to FAILURE"
                script{
                    currentBuild.result = "FAILURE"
                }
                echo "after setting current build to FAILURE"
            }
        }
    }
}
Ta thấy option retry ko kết hợp được với currentBuild.result = “FAILURE”
Chúng ta thấy stages đã được chạy thành công
currentBuild.result = “FAILURE”

option – timeout – steps – sleep

pipeline{
    agent any
    stages{
        stage("Build"){
            options{
                timeout(time: 1, unit: "SECONDS")
            }
            steps{
                echo "Hello"
                sleep 2
            }
        }
    }
}
timeout là 1s nhưng sleep step là 2s
nếu build đã bị Aborted

option – timestamp() – Invalid option type “timestamps”

Invalid

https://issues.jenkins.io/browse/JENKINS-48556

resolve above problem

Anh em biết cách fix chỉ mình nhé.

options-skipdefaultcheckout

https://github.com/mrnim94/pipeline-stage-options-skipdefaultcheckout.git
trong git bạn để ý có sẽ có Jenkinsfile

skip default checkout

Sau đó save và sem có điều j sảy ra

thấy jenkins ko có bước checkout code

don’t skip default checkout

command lại các phần checkout
jenkins slave đã thực hiện checkout code trên git

Bạn phần skip checkout bạn có thể đặt ở chỗ mình gọi:
– global pipeline: effect toàn pipeline
– stages: effect từng pipeline

Agent of agent
Bạn sẽ thấy slave jenkins trên k8s sẽ tạo pod jenkins trên k8s

Jenkins permanent mình cài trên k8s theo cách này:

[Jenkins] Install Jenkins StandAlone in Kubernetes
Kiểm tra lại workspace
exec vào jenkins slave kiểm tra
Jenkins master thì ko có workspace skip checkout
Jenkins

Post navigation

Previous Post: [Jenkins] Lesson 2: Using simple Groovy into Pipeline Script
Next Post: [Jenkins] Lesson 4: Environment in Pipeline Jenkins

More Related Articles

[Jenkins] Share Libraries 6: Closures Jenkins
[Jenkins – Gitlab] Cấu hình Gitlab Group trên Jenkins và auto thêm webhook Jenkins trên Gitlab CI/CD
[Jenkins] Share Libraries 9: Defining Pipeline Script In Call Method Jenkins
[Jenkins] Scripted Pipeline lesson 7: Stage _ Post Jenkins
[Jenkins] Scripted Pipeline lesson 12: Options _ CheckoutToSubdirectory. Jenkins
[Jenkins] Share Libraries 1: Global Function 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

  • 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
  • [Postgresql] Install postgresql client and trying a few command postgresql. June 20, 2022
  • [Mount/Nextcloud] How do you mount a hard disk that was used windows into Linux. June 19, 2022

Archives

  • 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.