英文:
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')
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论