【问题标题】:Using Jenkins Declarative Pipeline in Openshift, how to expose a service after calling openshift.newApp?在Openshift中使用Jenkins Declarative Pipeline,调用openshift.newApp后如何暴露服务?
【发布时间】:2018-11-13 11:37:40
【问题描述】:

我在 jenkins 中使用声明式管道在 OpenShift 中构建和部署。

这是我的 Jenkins 文件。

def indicator=false
pipeline{
    agent any

        parameters{   
            string(name: 'NAME', defaultValue: 'hello-world')
        }
        stages{
            stage('Run newApp then expose service'){
                when{
                    expression{
                        openshift.withCluster(){
                            return !openshift.selector('bc', params.NAME).exists()
                        }
                    }
                }
                steps{
                    script{
                        openshift.withCluster(){
                            openshift.withProject() {
                                def bc = openshift.newApp("registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift~ssh://git@gitlab.blah/projects/spring-boot/helloworld.git#feature/poc1", "--name=hello-world", "--source-secret=ssh-key").narrow('bc')
                                indicator = true
                                bc.logs("-f")

                                def buildSelector = bc.related("builds")

                                timeout(10) { // Throw exception after 5 minutes
                                    buildSelector.untilEach(1) {
                                        return (it.object().status.phase == "Complete")
                                    }
                                }
                                echo "Builds have been completed: ${buildSelector.names()}"
                                echo "Exposing ${params.NAME}"
                                bc.narrow('svc').expose
                            }
                        }
                    }
                }

            }
            stage('Start build'){
                steps{
                    script {
                        echo "Indicator value = ${indicator}"
                        if (!indicator) {
                            openshift.withCluster() {
                                openshift.withProject() {
                                    def bc  = openshift.selector('bc', params.NAME).narrow('bc')
                                    bc.startBuild()
                                }
                            }
                        }
                    }
                }
            }
        }
}

基本上我要做的是调用 oc newApp 来创建构建/部署配置、pod 和服务。我也想在之后公开服务。

创建了 bc/dc/service/pods 对象,但问题是我无法公开它。我在下面有这个错误。

另外,Jenkins Pipeline Dsl for Openshift (https://github.com/openshift/jenkins-client-plugin) 中的另一件事,如何做一个条件来测试服务是否已经公开,例如 if (service.IsExpose)?

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.GroovyObject getProperty java.lang.String (com.openshift.jenkins.plugins.OpenShiftDSL$OpenShiftResourceSelector.expose)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:180)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor$11.reject(SandboxInterceptor.java:330)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:381)
    at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:284)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:288)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at WorkflowScript.run(WorkflowScript:46)
    at com.openshift.jenkins.plugins.OpenShiftDSL.withProject(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:348)
    at com.openshift.jenkins.plugins.OpenShiftDSL$Context.run(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:120)
    at com.openshift.jenkins.plugins.OpenShiftDSL.withProject(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:347)
    at WorkflowScript.run(WorkflowScript:22)
    at com.openshift.jenkins.plugins.OpenShiftDSL.withCluster(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:336)
    at com.openshift.jenkins.plugins.OpenShiftDSL$Context.run(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:120)
    at com.openshift.jenkins.plugins.OpenShiftDSL.withCluster(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:335)
    at com.openshift.jenkins.plugins.OpenShiftDSL.node(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:1459)
    at com.openshift.jenkins.plugins.OpenShiftDSL.withCluster(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:292)
    at WorkflowScript.run(WorkflowScript:21)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
    at sun.reflect.GeneratedMethodAccessor160.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:331)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

【问题讨论】:

  • 你在哪里授权了 openshift cred?
  • 我在 openshift 内部运行 jenkins,所以我们使用了他们的模板,因此当您转到管理 Jenkins 部分时,连接到 openshift 的配置位于 cloud-kubernetes 部分

标签: jenkins openshift jenkins-pipeline


【解决方案1】:

对于这个异常 org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException

我只需要在 Jenkins 中进行手动脚本审批。

【讨论】:

    猜你喜欢
    • 2022-01-24
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    相关资源
    最近更新 更多