2017-06-14 131 views
0

由于多种原因,如果我可以从Jenkins管道创建文件并将其放入工作区,这将非常有用。如果我能做到这一点,我可以避免拉入一些存储库,因为我目前只将它们拖入一两个文件,将这些文件保存在可维护的位置,我也可以使用它创建临时PowerShell脚本,解决问题在https://stackoverflow.com/a/42576572Jenkins管道 - 在工作区创建文件(Windows从站)

中描述的解决方案的限制这可能通过管道实用程序,尽管https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/未列出任何此类实用程序;或者它可能使用批处理脚本可以 - 只要能作为字符串传递在

回答

1

你可以做这样的事情:

node (''){ 
    stage('test'){ 
    bat """ 
     echo "something" > file.txt 
    """ 
    String out = readFile(file.txt).trim() 
    print out // prints variable out groovy style 
    out.useFunction() // allows running functions loaded from the file 
    bat "type %out%" // batch closure can access the variable 
    } 
} 
+0

三江源 - 有没有办法,我可以做到这一点与多行呢?我希望使用的配置文件和脚本跨越多行。 – penguat

+0

你会在这个SO问题中找到你的答案:https://stackoverflow.com/questions/7954719/how-can-a-batch-script-do-the-equivalent-of-cat-eof –