Chúng ta có file groovy trong share library trên github – Khép kín
https://github.com/mrnim94/pipeline-shared-lib/blob/master/vars/executeInScript.groovy
def call(Closure body) {
script{
body()
}
}
chúng ta có thấy điều đặc biệt là họ chuyền luôn block script vào trong file grooy luôn
Dưới này là file script của chúng ta.
@Library("pipeline-shared-lib") _
pipeline{
agent{
label 'docker-maven'
}
stages{
stage("Build"){
steps{
executeInScript({
sh 'printenv'
})
}
}
}
}
Ở đây chúng ta thấy truyền string { sh 'printenv' }
vào body của func executeInScript