Nếu bạn đang chạy một bước trong một dự án sau đó có một biến môi trường JOB_NAME
mà trong groovy bạn có thể truy cập vào
String jobName = System.getenv('JOB_NAME')
Nếu bạn muốn nó gửi build sau đó kiểm tra câu trả lời này How to get specific information about the current build project in Jenkins with Groovy?
Theo câu hỏi bổ sung, để có quyền truy cập vào tên công việc Jenkins ở giai đoạn thiết lập bạn cần sử dụng EnvInject plugin mà hỗ trợ groovy - nó cần phải trả lại một bản đồ
println "currentJob -->${currentJob}"
println "currentBuild --> ${currentBuild}"
[currentJob: currentJob, currentBuild: currentBuild]
Đây là đầu ra khi tôi sử dụng một công việc vỏ để echo môi trường mới
Started by user anonymous
[EnvInject] - Loading node environment variables.
[EnvInject] - Preparing an environment for the build.
[EnvInject] - Keeping Jenkins system variables.
[EnvInject] - Keeping Jenkins build variables.
[EnvInject] - Evaluation the following Groovy script content:
println "currentJob -->${currentJob}"
println "currentBuild --> ${currentBuild}"
[currentJob: currentJob, currentBuild: currentBuild]
currentJob -->[email protected][_xxx]
currentBuild --> _xxx #6
[EnvInject] - Injecting contributions.
Building on master in workspace /var/lib/jenkins/workspace/_xxx
[_xxx] $ /bin/sh -xe /tmp/hudson3812821436584477615.sh
+ echo _xxx #6
_xxx #6
+ echo [email protected][_xxx]
[email protected][_xxx]
Finished: SUCCESS
Bạn cần phải làm một số thao tác chuỗi để tách biệt công việc và xây dựng
Cảm ơn bạn rất nhiều –
Man, trong tham số động này không hoạt động –
Bạn nói đúng. nếu bạn làm điều này trong thuộc tính động 'System.getenv(). mỗi {println it}' thì nó không liệt kê môi trường JENKINS. – KeepCalmAndCarryOn