我將檔案路徑字串分成兩個單獨的字串:
- 僅包含目錄的檔案路徑(已洗掉檔案名)
- 檔案名
我想在 CPS 背景關系中作業,這可以防止一些閉包的使用。我有以下作業代碼,但我不確定這是否是好的做法。檔案路徑參考名為“idver.h”的“ID 版本”檔案。'projectPaths' 是包含檔案路徑的映射。
//pull off the filename from end of filepath
String[] idVerPathArray = projectPaths.idVerPath.split('/')
String filename = idVerPathArray.last()
//get subarray without last element
String[] idVerJustPathArray = Arrays.copyOfRange(idVerPathArray, 0, idVerPathArray.length - 1)
String idVerJustPath = idVerJustPathArray.join('/')
uj5u.com熱心網友回復:
def file = new File(projectPaths.idVerPath)
String filename = file.name
String idVerJustPath = file.parent
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/434584.html
標籤:詹金斯 时髦的 jenkins-groovy
