如何避免Jenkins在受信任的共享管道中请求流程中的呼叫批准

时间:2019-07-08 15:54:18

标签: jenkins jenkins-pipeline jenkins-shared-libraries

TLDR;

如何以非交互方式配置jenkins,以便人们可以使用我的共享库而无需我单击处理中脚本的批准按钮

长话...

我在Jenkins中创建了一个共享库,它看起来像这样(简化版):

def call(body) {
    // evaluate the body block, and collect configuration into the object
    def pipelineParams= [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = pipelineParams
    body()

    pipeline { stages { stage { steps { script {
        pipelineParams.test()
    }
}

这样,用户可以像这样调用我的图书馆:

@Library('my-shared-library@master') _
MyPipeline {
    test = {
        sh "./gradlew test"
    }
}

该库还配置在 jenkins / configure 下。

麻烦是詹金斯总是要征求进程中的笔迹批准

  

签名:staticMethod   org.codehaus.groovy.runtime.DefaultGroovyMethods invokeMethod   java.lang.Object java.lang.String java.lang.Object

但是在文档中却说共享库应该是受信任的https://jenkins.io/doc/book/pipeline/shared-libraries/#global-shared-libraries ...

这是我尝试过的:

1。完全禁用进程内脚本批准

这似乎是不可能的:请参见How can I disable security checks for Jenkins pipeline builds并打开jenkins票证:https://issues.jenkins-ci.org/browse/JENKINS-28178

2。使用“配置为代码”预先配置詹金斯以允许这种特定方法

目前尚无法实现……工作似乎已经准备就绪,但直到今天仍需要合并到母版中:https://github.com/jenkinsci/script-security-plugin/pull/250

3。在jenkins / scriptApproval上进行GET和POST

我使用浏览器调试器来查看进行了哪些调用。页面上的GET为我提供了正确的ID,然后执行POST就足够了,但是由于两个请求是分别发出的,因此ID之间会发生变化,并且我收到404错误...

import requests
id = [line for line in requests.get("http://localhost:8080/scriptApproval/").text.strip().split() if 'makeStaplerProxy' in line][0].split("'")[1]
postUrl = "http://localhost:8080" + id + "/approveSignature"
print(postUrl)
r = requests.post(postUrl)
print(r.status_code)

将给出:

http://localhost:8080/$stapler/bound/8488d0c2-9fce-4091-8b9f-747ae0016421/approveSignature
404

4。隐式加载库

我隐式加载库,并删除了

@Library('my-shared-library@master') _
Jenkins文件中的

。仍然需要批准。

没有想法

我完全没有主意。通常来说,共享管道应该是受信任的,所以我不明白为什么他仍然要求批准这些外部呼叫……或者我在实现我的过程中做错了什么共享库?

0 个答案:

没有答案