在 Jenkinsfile 中,如何在 `sh` 步骤中执行多行 Shell 命令
在 Jenkinsfile 中,当你需要在
sh
步骤中执行多行 Shell 命令时,可以通过多种方式来实现。直接分行传参通常需要适当的字符串处理来确保命令的正确解析和执行。以下是一些实现多行命令的方法:
1. 使用多行字符串
你可以使用三引号("""
)来定义多行字符串,这在 Groovy 中用于表示一个字符串跨越了多行:
pipeline {
agent any
stages {
stage('Multi-line shell commands') {
steps {
script {
sh """