如何在文件中添加可变内容?
sh "ssh root@${host} 'echo '$vari' > text.txt'"
这将提供空文件
没有变量,它可以工作:
sh "ssh root@${host} 'echo some text > text.txt'"
答案 0 :(得分:0)
有两种方法可以将变量的内容写入文件:
pipeline {
agent any
environment {
VAR = "hello world!"
}
stages {
stage('Write to file'){
steps{
sh 'echo "${VAR}" > test.txt'
sh "echo ${VAR} >> test.txt"
sh 'cat test.txt'
}
}
}
}
输出:
[test] Running shell script
+ echo hello world!
[Pipeline] sh
[test] Running shell script
+ echo hello world!
[Pipeline] sh
[test] Running shell script
+ cat test.txt
hello world!
hello world!