I'm setting up a jenkins job which will be triggered whenever a artifact is deployed in jfrog. I have followed the steps present in the below documentation and i was able to trigger the job.But unfortunately, i'm not able to get the variables values.I'm not sure how to see the payload which we are receiving on the jenkins side to pull the required variables.Guide me
https://www.eficode.com/blog/triggering-jenkins-pipelines-on-artifactory-events
My pipeline:
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 job logs:
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$2.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$2.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
CodePudding user response:
I'd like to suggest a different approach using the
Or you can configure the build trigger in the pipeline:
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"
)
}
}
}
To get the path in Artifactory that caused the trigger you can do the following:
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}"
}
Resources: