jenkins - 如何从 Jenkinsfile 步骤中删除脚本中的脚本
问题描述
我不确定如何在声明性 Jenkinsfile 中解开这一步。有人告诉我你不能在脚本中包含脚本,所以我正在寻求有关如何重构它的帮助。
stage('Publish Procurement') {
steps {
script: '''
if (0 != sh(script: "git diff --exit-code modules/procurement", returnStatus: true)) {
node_modules/.bin/ng build test-library
cd modules/test-library/dist/
node_modules/.bin/ng test test-library
}
'''
}
}
我感谢提供的任何帮助。
解决方案
尝试这个 :
stage('Publish Procurement') {
steps {
returnCode = sh(script: "git diff --exit-code modules/procurement", returnStatus: true)
if ( 0 != returnCode){
script: '''
node_modules/.bin/ng build test-library
cd modules/test-library/dist/
node_modules/.bin/ng test test-library
'''
}
}
}
您始终可以将 sh 的输出存储到变量中,然后使用该变量执行任何类型的有效操作。
推荐阅读
- ios - 使用 alamofire 和 swifty json 将图像上传到 Web 服务返回错误失败
- c++ - 我不明白 `cin` 在 C++ 中的工作原理
- angularjs - AngularJs
在菜单外单击时不会关闭 - java - 单击按钮时无法打开网络应用程序
- python - 如何从具有相同键值的两个字典创建熊猫数据框?
- objective-c - tableview 内的collectionview 使用动态单元格高度展开折叠。目标c
- python - python中'for'和'while'循环之间的工作原理
- session - 通过询问 IDP 确认活动会话
- ajax - ajax 成功调用后 this.navCtrl 未定义
- python - 使用python连接到交换机内的特定端口