jenkins Kubernetes连通性测试脚本

58wvjzkj  于 2023-03-17  发布在  Jenkins
关注(0)|答案(1)|浏览(175)

我想创建一个Jenkins脚本,使用以下代码测试连通性:

pipeline {
    agent any
    environment {
    }
    
  stages{    
    stage('Ping Kubernetes') {
            steps {
                
                script{
                         sh '
                             curl -k  https://localhost:6443/api/v1/namespaces -H "Authorization: Bearer eyJhbGciOiJSUzI......"
                         '
                    }
                }

            }                
        }    
    }
    
}

但我得到错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 11: unexpected char: ''' @ line 11, column 29.
                            sh '

您知道如何解决此问题吗?

lmvvr0a8

lmvvr0a81#

您正在使用多行字符串,但语法不正确(三重引号)
由于只有一行,您可以执行以下操作:

sh 'curl -k  https://localhost:6443/api/v1/namespaces -H "Authorization: Bearer eyJhbGciOiJSUzI......"'

如果你想使用多行字符串,则为:

sh '''
   curl -k  https://localhost:6443/api/v1/namespaces -H "Authorization: Bearer eyJhbGciOiJSUzI......"
'''

相关问题