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
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • 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]Scripted Pipeline lesson 15: Parameters. Jenkins
[Jenkins] Share Libraries 7: Importing Third-Party Libraries Jenkins
[Jenkins] Lesson 1: Hello World – Pipeline Script & Agent Jenkins
[Jenkins] Scripted Pipeline lesson 14: Options _ NewContainerPerStage. Jenkins
[Jenkins] Lesson 9: Using buildDiscarder to keep build history in Jenkins Jenkins
[Jenkins] Scripted Pipeline lesson 19: Triggers _ Upstream 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

  • [Smartctl] Instruction check the health disk of Raspberry. January 16, 2023
  • [kubectl/Argocd] How to create a kubectl config file for serviceaccount or from the cluster secret of Argocd January 12, 2023
  • [Helm/Github] Create a public Helm chart repository with GitHub Pages January 8, 2023
  • [AWS] How to increase the disk size of a Windows EC2 machine? January 4, 2023
  • [Redis] ElastiCache-Redis Cross-Region Replication|Global DataStore January 3, 2023

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • 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
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • Golang
    • Jquery & JavaScript
    • Laravel
    • Python
    • 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 © 2023 NimTechnology.