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
      • Pod
    • Helm Chart
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Jenkins] Share Libraries 8: Loading Resources

Posted on November 11, 2021December 1, 2021 By nim No Comments on [Jenkins] Share Libraries 8: Loading Resources

Như giới thiệu ở bài đầu tiên, thư mục resources chưa các file ko phải là Groovy

Trong resources mình để 1 file Json

https://github.com/mrnim94/pipeline-shared-lib/blob/master/resources/com/acceleratedskillup/request.json

{
	name:"test",
	height:1.55
}

giờ chúng ta có script như sau:

@Library("pipeline-shared-lib") _
pipeline{
   agent{
       label 'docker-maven'
   }

    stages{
        stage("Build"){
            steps{
                script{
                    def request = libraryResource 'com/acceleratedskillup/request.json'
                    echo request
                }
            }
        }
    }
}

Giờ save

Anh Em sẽ thấy 1 thứ là libraryResouce

material reference about libraryResouce
https://www.jenkins.io/doc/book/pipeline/shared-libraries/#loading-resources
https://www.jenkins.io/doc/pipeline/steps/workflow-cps-global-lib/

Chúng ta có vẫn đề là bạn thấy jenkins master sẽ control jenkins agent.
nhưng mà jenkins agent sẽ không git clone hay git clone pipeline-shared-lib về con agent
bạn có thể kiểm chừng thêm các câu lệnh ls -la để kiểm tra

Vậy là nếu bạn để 1 file script.sh ở resource và bạn muốn agent chạy nó, thì sẽ ko được. tại nó pull file đó về agent đâu. ý à. vậy làm sao?

Có 1 anh tây nói rất chi tiết về vấn đề này.

Sem rồi thì lab theo ảnh thôi.

https://github.com/mrnim94/pipeline-shared-lib

Chúng ta sẽ đi từ pipeline script:

@Library("pipeline-shared-lib") _
pipeline{
   agent{
       label 'docker-maven'
   }

    stages{
        stage("Build"){
            steps{
                script{
                    helloWorldExternal(name: "nimtechnology", dayOfWeek: "Monday")
                }
            }
        }
    }
}

Phân tích chúng ta thấy underscore “_” là nó sẽ sử global function ở var

Nó sẽ sử dụng file này

def call() nhận các parameter từ pipeline script
load 1 global function khác và truyền name qua đó
xong nó run file script .sh

sau bước này là nó tạo file script rồi con jenkins agent chạy thôi

Jenkins

Post navigation

Previous Post: [Jenkins] Share Libraries 7: Importing Third-Party Libraries
Next Post: [Grafana/Prometheus] Grafana Chars display “NA” value

More Related Articles

[Jenkins] Hướng dẫn kết nối kết nối Jenkins master và Agent CI/CD
[Jenkins – Kubernestes] Jenkins tạo Jenkins slave trên Kubernetes CI/CD
[Jenkins] Lesson 3: Option in Pipeline Jenkins Jenkins
[Jenkins] Lesson 1: Hello World – Pipeline Script & Agent Jenkins
[Kaniko/Jenkins] Install Jenkins through helm and build/deploy app in K8s by Kaniko CI/CD
[Jenkins] Lesson 10: disable Concurrent Builds in 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

  • [Terraform / EKS] Build EKS and Karpenter by Terraform. September 22, 2023
  • [EKS] Adjusting things to migrate EKS legacy to new versions. September 19, 2023
  • [Tetragon] Security Observability and Runtime Enforcement September 17, 2023
  • [Docker] Setup Docker for Windows Containers (NO Docker Desktop Needed!) September 15, 2023
  • [Python] Python connects MongoDB September 15, 2023

Archives

  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • 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
    • NextCloud
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • 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
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2023 NimTechnology.