Passing A File Created Using Powershell To Jenkinsfile

huangapple go评论58阅读模式
英文:

Passing A File Created Using Powershell To Jenkinsfile

问题

我在Jenkinsfile中使用Powershell创建了一个文件:

pwsh(returnStdout: true, script: '. "' + env.WORKSPACE + '/folder/functions.ps1"'
  $serversList = (Get-servers).keys | out-file - FilePath .\\serversList.txt

当我使用Groovy查找时,无法找到这个文件。我希望能够传递这个文件并在我的Jenkinsfile中使用它。

我在网上找不到任何关于这个用例的答案。

非常感谢任何帮助。

英文:

I created a file using Powershell within Jenkinsfile:

pwsh(returnStdout: true, script: '. "' + env.WORKSPACE + '/folder/functions.ps1"' + '''

  $serversList = (Get-servers).keys | out-file - FilePath .\\serversList.txt

'''

I am unable to find this file when looking for it using Groovy. I wish to pass this file and use it in my jenkinsfile.

I was unable to find any answer for this use case online.

Any help will be very appreciated.

答案1

得分: 1

你应该首先确保该文件实际上是由登录到Jenkins主机机器并手动查看而创建的。如果文件确实存在,请记下其位置,并使用 dir 指定目录。然后使用 readFile 读取文件的内容:

dir("path\\to\\serversList.txt") {
    def data = readFile(file: 'serversList.txt')
}
英文:

You should first ensure that the file was actually created by logging into the Jenkins host machine and looking there manually. If the file is indeed there, note its location and use dir to specify the directory first. Then use readFile to read the contents of the file:

dir("path\\to\\serversList.txt"){
    def data = readFile(file: 'serversList.txt')
}

huangapple
  • 本文由 发表于 2023年4月20日 03:49:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058309.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定