Jenkins groovy - java расширение без прав - PullRequest
0 голосов
/ 14 июля 2020

У меня есть простой файл Jenkins со следующим содержимым:

@Library('BMS-Libraries')
import static bms.utils.Utils.*

node('MyNode') {
    stage('Build') {
        updateAssemblyVersion(this, "${env.WORKSPACE}", "${fullVersion}")
    }
}

И у меня есть файл Utils. groovy со следующим содержимым:

@NonCPS
static def updateAssemblyVersion(script, path, version){
    def fileExtensions = new String[1];
    fileExtensions[0] = "AssemblyInfo.cs";

    def p = Paths.get(path.toString());
    script.echo "Updating versions in AssemblyInfos in directory ${p.toString()}"
    def user = System.getProperty("user.name");
    script.echo "Current user is ${user}"
    if(Files.notExists(p)){
        script.echo "${p.toString()} does not exist!"
    }
    def files = FileUtils.iterateFiles(new File(p.toString()), new NameFileFilter(fileExtensions), TrueFileFilter.INSTANCE);

    for(def file: files){
        script.echo "Updating Versions in AssemblyInfo file ${file} ..."
        def content = new String(file.readBytes());
        content = content.replaceAll("AssemblyVersion\\(\".*\"\\)", "AssemblyVersion(\"${version}\")");

        file.write(content)
    }
}

Я вижу в узле , что каталог, указанный в "$ {env.WORKSPACE}", существует, но вывод сценария всегда следующий:

[Pipeline] echo
Updating versions in AssemblyInfos in directory C:\TEST\workspace\ProjectName
[Pipeline] echo
Current user is PWEU0019BMS01$
[Pipeline] echo
C:\TEST\workspace\ProjectName does not exist!
java.lang.IllegalArgumentException: Parameter 'directory' is not a directory: C:\TEST\workspace\ProjectName

Интересно насчет имени пользователя «PWEU0019BMS01 $»? Это не пользователь, существующий на узле, а имя мастера. Похоже, у исполняемого кода нет прав на доступ к каталогу.

...