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] 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] Scripted Pipeline lesson 14: Options _ NewContainerPerStage. Jenkins
Hướng dẫn phần quền user trên Jenkins. CI/CD
[Jenkins] Share Libraries 4: Importing Static Libraries Jenkins
[Jenkins] Create User Jenkins and setup permission this one. Jenkins
[jenkins] Scripted Pipeline lesson 3: Stage _ Options Jenkins
[Jenkins]Scripted Pipeline lesson 15: Parameters. 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.