如何从jenkins上的jfrog webhook触发器获取有效负载信息
How to get the payload information from jfrog webhook trigger on jenkins
我正在设置一个 jenkins 作业,每当在 jfrog 中部署工件时都会触发该作业。我已按照以下文档中的步骤进行操作,不幸的是我能够触发 job.But,我无法获取变量 values.I 我不确定如何查看我们的有效负载在 jenkins 端接收以拉取所需的 variables.Guide me
https://www.eficode.com/blog/triggering-jenkins-pipelines-on-artifactory-events
我的管道:
pipeline {
agent any
triggers {
GenericTrigger(
genericVariables: [
[key: 'ARTIFACT_NAME', value: '$.artifactory.webhook.data.name'],
[event: 'EVENT_NAME', value: '$.artifactory.webhook.event']
],
causeString: 'Triggered on $ARTIFACT_NAME'
)
}
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}
Jenkins 作业日志:
java.lang.NullPointerException: Variable name
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:204)
at org.jenkinsci.plugins.gwt.GenericVariable.<init>(GenericVariable.java:31)
Caused: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedConstructorAccessor6020.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:330)
Caused: java.lang.IllegalArgumentException: Could not instantiate {event=EVENT_NAME, value=$.artifactory.webhook.event} for org.jenkinsci.plugins.gwt.GenericVariable
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:334)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:474)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:585)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:458)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:272)
at org.jenkinsci.plugins.pipeline.modeldefinition.CommonUtils.instantiateDescribable(CommonUtils.java:131)
at org.jenkinsci.plugins.pipeline.modeldefinition.CommonUtils$instantiateDescribable.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at org.kohsuke.groovy.sandbox.impl.Checker.call(Checker.java:194)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onStaticCall(GroovyInterceptor.java:35)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onStaticCall(SandboxInterceptor.java:186)
at org.kohsuke.groovy.sandbox.impl.Checker.call(Checker.java:192)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedStaticCall(Checker.java:196)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:103)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
Caused: java.lang.IllegalArgumentException: Could not instantiate {genericVariables=[{key=ARTIFACT_NAME, value=$.artifactory.webhook.data.name}, {event=EVENT_NAME, value=$.artifactory.webhook.event}], causeString=Triggered on $ARTIFACT_NAME} for org.jenkinsci.plugins.gwt.GenericTrigger
我想建议使用 Jenkins Artifactory plugin 的不同方法:
您可以在 UI 中配置构建触发器:
或者您可以在管道中配置构建触发器:
stages {
stage('Artifactory configuration') {
steps {
rtServer(
id: "ARTIFACTORY_SERVER",
url: SERVER_URL,
credentialsId: CREDENTIALS
)
}
}
stage('Add build trigger') {
steps {
rtBuildTrigger(
serverId: "ARTIFACTORY_SERVER",
spec: "*/10 * * * *",
paths: "generic-libs-local/builds/starship"
)
}
}
}
要获取导致触发器的 Artifactory 路径,您可以执行以下操作:
environment {
// The URL of the artifact in Artifactory, caused the job to be triggered.
// May be empty if the build isn't triggered by a change in Artifactory.
RT_TRIGGER_URL = "${currentBuild.getBuildCauses('org.jfrog.hudson.trigger.ArtifactoryCause')[0]?.url}"
}
资源:
我做到了。我们必须在通用 webhook 触发器选项下的配置 jenkins 作业中启用打印 post 内容。完成后,它开始在控制台日志中显示 json 负载。之后我们可以使用 jsonpath filter from payload
添加变量
我正在设置一个 jenkins 作业,每当在 jfrog 中部署工件时都会触发该作业。我已按照以下文档中的步骤进行操作,不幸的是我能够触发 job.But,我无法获取变量 values.I 我不确定如何查看我们的有效负载在 jenkins 端接收以拉取所需的 variables.Guide me
https://www.eficode.com/blog/triggering-jenkins-pipelines-on-artifactory-events
我的管道:
pipeline {
agent any
triggers {
GenericTrigger(
genericVariables: [
[key: 'ARTIFACT_NAME', value: '$.artifactory.webhook.data.name'],
[event: 'EVENT_NAME', value: '$.artifactory.webhook.event']
],
causeString: 'Triggered on $ARTIFACT_NAME'
)
}
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}
Jenkins 作业日志:
java.lang.NullPointerException: Variable name
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:204)
at org.jenkinsci.plugins.gwt.GenericVariable.<init>(GenericVariable.java:31)
Caused: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedConstructorAccessor6020.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:330)
Caused: java.lang.IllegalArgumentException: Could not instantiate {event=EVENT_NAME, value=$.artifactory.webhook.event} for org.jenkinsci.plugins.gwt.GenericVariable
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:334)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:474)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:585)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:458)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:272)
at org.jenkinsci.plugins.pipeline.modeldefinition.CommonUtils.instantiateDescribable(CommonUtils.java:131)
at org.jenkinsci.plugins.pipeline.modeldefinition.CommonUtils$instantiateDescribable.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at org.kohsuke.groovy.sandbox.impl.Checker.call(Checker.java:194)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onStaticCall(GroovyInterceptor.java:35)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onStaticCall(SandboxInterceptor.java:186)
at org.kohsuke.groovy.sandbox.impl.Checker.call(Checker.java:192)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedStaticCall(Checker.java:196)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:103)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
Caused: java.lang.IllegalArgumentException: Could not instantiate {genericVariables=[{key=ARTIFACT_NAME, value=$.artifactory.webhook.data.name}, {event=EVENT_NAME, value=$.artifactory.webhook.event}], causeString=Triggered on $ARTIFACT_NAME} for org.jenkinsci.plugins.gwt.GenericTrigger
我想建议使用 Jenkins Artifactory plugin 的不同方法:
您可以在 UI 中配置构建触发器:
或者您可以在管道中配置构建触发器:
stages {
stage('Artifactory configuration') {
steps {
rtServer(
id: "ARTIFACTORY_SERVER",
url: SERVER_URL,
credentialsId: CREDENTIALS
)
}
}
stage('Add build trigger') {
steps {
rtBuildTrigger(
serverId: "ARTIFACTORY_SERVER",
spec: "*/10 * * * *",
paths: "generic-libs-local/builds/starship"
)
}
}
}
要获取导致触发器的 Artifactory 路径,您可以执行以下操作:
environment {
// The URL of the artifact in Artifactory, caused the job to be triggered.
// May be empty if the build isn't triggered by a change in Artifactory.
RT_TRIGGER_URL = "${currentBuild.getBuildCauses('org.jfrog.hudson.trigger.ArtifactoryCause')[0]?.url}"
}
资源:
我做到了。我们必须在通用 webhook 触发器选项下的配置 jenkins 作业中启用打印 post 内容。完成后,它开始在控制台日志中显示 json 负载。之后我们可以使用 jsonpath filter from payload
添加变量