P. *_*tty 4 jenkins jenkins-pipeline
我有Jenkins 2.19.4 with Pipeline:Declarative Agent API 1.0.1.如果你不能定义一个变量来分配读取的属性,那么如何使用readProperties?
例如,要捕获SVN修订版号,我目前使用以下脚本样式捕获它:
```
echo "SVN_REVISION=\$(svn info ${svnUrl}/projects | \
grep Revision | \
sed 's/Revision: //g')" > svnrev.txt
Run Code Online (Sandbox Code Playgroud)
```
def svnProp = readProperties file: 'svnrev.txt'
Run Code Online (Sandbox Code Playgroud)
然后我可以使用:
${svnProp['SVN_REVISION']}
Run Code Online (Sandbox Code Playgroud)
由于在声明式样式中def svnProp不合法,readProperties如何使用?
Jon*_*n S 11
您可以使用标记script内的步骤steps来运行任意管道代码.
所以有以下几点:
pipeline {
agent any
stages {
stage('A') {
steps {
writeFile file: 'props.txt', text: 'foo=bar'
script {
def props = readProperties file:'props.txt';
env['foo'] = props['foo'];
}
}
}
stage('B') {
steps {
echo env.foo
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里我使用env在各阶段之间传播值,但也许可以做其他解决方案.
| 归档时间: |
|
| 查看次数: |
10108 次 |
| 最近记录: |