我正在尝试用groovy创建一个自定义管道,但是我在web上找不到任何地方讨论如何添加可以在jenkinsfile中设置的属性。我试图添加一个curl命令,但是需要在jenkinsfile中设置URL,因为对于每个构建,它都是不同的。
有谁能解释一下该怎么做,或者在什么地方讨论过呢?
示例Jenkinsfile:
msBuildPipelinePlugin
{
curl_url = "http://webhook.url.com"
}自定义管道groovy代码:
def response =sh(脚本:'curl -i -X POST -H 'Content-Type: application/json‘-d '{"text","Jenkins Info。\n这是更多的文本“}’curl_url,returnStdout: true‘)
谢谢
发布于 2020-02-27 23:01:24
我用的是
//response只是curl语句的输出
def response = "curl“、"-i”、"-v“、"-X”、"POST“、”-data-urlencode“、”payload={\“text\:\”message body\“}、"curl url”在这里“.execute().text”
谢谢
发布于 2019-10-18 03:35:48
如果要在每次生成期间将URL指定为字符串,则可以执行以下操作之一:
声明管道
使用parameters {}指令:
pipeline {
agent {
label 'rhel-7'
}
parameters {
string(
name: 'CURL_URL',
defaultValue: 'http://www.google.com',
description: 'Enter the URL for file download'
)
}
stages {
stage('download-file') {
steps {
echo "The URL is ${params.CURL_URL}"
}
}
}
}脚本管道
使用properties([parameters([...])])步骤:
parameters([
string(
name: 'CURL_URL',
defaultValue: 'http://www.google.com',
description: 'Enter the URL for file download'
)
])
node('rhel-7') {
stage('download-file') {
echo "The URL is ${params.CURL_URL}"
}
}您可以选择将defaultValue和description的值保留为空。
作业GUI
上述任何一种语法都将在GUI中呈现为:

https://stackoverflow.com/questions/58443178
复制相似问题