Bài này khó vl các bạn ạ.
Mình không rành java nên mình hiểu đến đâu mình giải thích đến đó nhé. Mong các bạn thông cảm.
groovy file trên share library của chúng ta
https://github.com/mrnim94/pipeline-shared-lib/blob/master/src/com/acceleratedskillup/Car.groovy

In this function, we are using the echo step from the script object to print out the properties.
Bài này mình sẽ có 1 số link để các bạn tìm hiểu thêm.
Link này giúp các bạn hiểu khai báo def xxx
https://stackoverflow.com/questions/54831615/is-there-a-way-to-specify-a-constructor-for-a-groovy-script

Các bạn thấy file groovy của chúng ta sử dụng contructor mặc định
https://viettuts.vn/java/constructor-trong-java
Giờ anh em tạo pipeline trên jenkins. với script như sau:
@Library("pipeline-shared-lib")
import com.acceleratedskillup.*;
pipeline{
agent any
stages{
stage("Build"){
steps{
script{
def car = new Car(this)
car.numberOfDoors = 4
car.brand = "brandX"
car.model = "modelY"
car.printOutCar()
}
}
}
}
}
Mình chưa hiểu tại sao chỗ này có chứ thisdef car = new Car(this)
Mình nghe lùng bùng họ giải thích như sau:
We create a car object sending in this, which represents the line script object, the current pipeline end of the line here, and we also import the package of the class we want to use and inside the script

Bài này mình cũng hơi ngáo. nếu các bạn lab hiểu chi tiết hay comment để chỉ lại mình nhé.