I want to add a process step in my pipeline, that checks out a project from PTC Integrity. There is a example in the Snippet Generator for a checkin but it is not built correctly, so I can not take this for orientation.
As PTC Integrity is not properly documented for the use with SCM Step Plugin (although supported according to their compability list) I have no idea how to do this.
My first step was to Find out what if there is a Integrity SCM class with this pipeline script:
node {
checkout scm: [$class: 'IntegritySCM']
}
This throws as expected an IllegalArgumentException:
java.lang.IllegalStateException: cannot call getRootUrlFromRequest from outside a request handling thread
at jenkins.model.Jenkins.getRootUrlFromRequest(Jenkins.java:2366)
at hudson.scm.IntegritySCM.<init>(IntegritySCM.java:113)
Caused: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:260)
Caused: java.lang.IllegalArgumentException: Could not instantiate {serverConfig=d917f329-9826-4ffa-8bbd-de68271c4abd}
for IntegritySCM(browser: IntegrityRepositoryBrowser{IntegrityWebUI(url: String)}, serverConfig: String, userName: String, password: String, configPath: String, includeList: String,
excludeList: String, cleanCopy: boolean, lineTerminator: String, validCheckpoint: boolean, freezeMembers: boolean, noCheckout: boolean,
restoreTimestamp: boolean, skipAuthorInfo: boolean, checkpointBeforeBuild: boolean, checkpointLabel: String,
alternateWorkspace: String, fetchChangedWorkspaceFiles: boolean, deleteNonMembers: boolean, checkoutThreadPoolSize: int, configurationName: String)
From this I can conclude which arguments can be given for the checkout command.
Now my question is, how can I build the checkout command in the pipeline script?
I saw an example on the github page of the scm step plugin but for mercurial which does it like this:
checkout scm: [$class: 'MercurialSCM', 'source': '....', clean: true...]
But I can't apply this to Integrity. E.g. I don't know how to tell the command the path of the project I want to checkout.
The pipeline snippet generator tool can be used to generate a pipeline syntax for any SCM classes supported by Pipeline. You can take a look here: https://jenkins.io/blog/2016/05/31/pipeline-snippetizer/
A sample pipeline snippet is something like this:
checkout([$class: 'IntegritySCM', checkpointBeforeBuild: false, configPath: '\integrity project configuration path\', configurationName: '7fc7dc75-f94e-4cc7-ab57-558f611d0fb8', deleteNonMembers: false, fetchChangedWorkspaceFiles: false, localClient: true, password: '{AQAAABAAAAAQ7YBJmtuzpndmmu/eUEL3v80g/oF3g+lzpM1S1JHkk5E=}', restoreTimestamp: false, serverConfig: '836d9a67-b82d-4cf3-ba06-c4557a18306b', skipAuthorInfo: false])
Related
I have a multi-branch pipeline that uses a Jenkinsfile to load a shared library defined in my system configuration.
#Library("my-shared-library") _
import com.company.exa.builders.BaseBuilder
import com.company.exa.builders.EdiBuilder
import hudson.model.*
buildNumbers = getBuildNumbers() // Function not shown, but it works
properties ([
disableConcurrentBuilds(),
[$class: 'jenkins.model.BuildDiscarderProperty',
strategy: [$class: 'LogRotator',
numToKeepStr: '50',
artifactNumToKeepStr: '20']],
parameters ([
choiceParam(name: "VERSION_CHOICE",
choices: buildNumbers,
description: "Version from Builds"),
stringParam(name: "VERSION_PASSEDIN",
defaultValue: env.BRANCH_NAME,
description: "Passed-in version. Note this will override VERSION_CHOICE."),
booleanParam(name: "UPLOAD_ARTIFACTS",
defaultValue: false,
description: "Upload artifacts to file servers?"),
choiceParam(name: "DEBUG_LEVEL",
choices: ["0", "1", "2", "3"],
description: "Debug level; 0=less verbose, 3=most verbose")
])
])
When I run it clicking Scan Multibranch Pipeline Now, I get
00:00:01.018 Loading library my-shared-library
00:00:01.019 Attempting to resolve maser from remote references...
00:00:01.019 > git --version # timeout=10
00:00:01.023 > git --version # 'git version 2.17.1'
00:00:01.023 using GIT_SSH to set credentials Jenkins Master SSH
00:00:01.028 > git ls-remote -h -- git#bitbucket.org:cfouts-kmha/kmha-infrastructure.git # timeout=10
00:00:01.546 Found match: refs/heads//master revision a1bc1e273b41c4e892d7c25814d0f2a1c261f7e5
00:00:01.546 ERROR: Checkout failed
00:00:01.546 java.lang.IllegalArgumentException: Null value not allowed as an environment variable: VERSION_PASSEDIN
00:00:01.546 at hudson.EnvVars.put(EnvVars.java:379)
00:00:01.546 at hudson.model.StringParameterValue.buildEnvironment(StringParameterValue.java:59)
...complaining that variable VERSION_PASSEDIN is null. I've tried setting the VERSION_PASSEDINvariable to just "" in the following locations to no avail...
The multi-branch pipeline's Folder properties
The multi-branch pipeline's parent folder properties
In the Jenkinsfile itself
In the System configuration global properties
Any clues on how to fix this? I have a feeling it's something obvious that I'm not seeing.
Note that if I run the job with a branch's "Build with parameters" link, the job runs fine.
You have a chicken-and-egg problem when trying to set default value for parameters, e.g. here:
stringParam(name: "VERSION_PASSEDIN",
defaultValue: env.BRANCH_NAME,
To run your pipeline, Jenkins needs to figure out the value of the parameters. However, to figure out the value of the parameters, Jenkins needs to run your pipeline. See the problem?
To overcome this problem, here's what happens: Jenkins assumes the value of nothing for both VERSION_CHOICE and VERSION_PASSEDIN. In the first case, it's an empty choice; in the second, it's null.
I'm trying to specify the GithubProjectProperty in a Jenkins Multibranch pipeline. I've been unsuccessful attempting to set an entry in the option block to control this value.
The pipeline syntax snippet generator suggests:
properties([
$class: 'GithubProjectProperty',
displayName: '',
projectUrlStr: 'https://myServer/myOrg/myRepo'
])
None of the following appear to work:
1) Try to put the properties directly in the options block
options {
// Set the URL for the GitHub project option
properties([
$class: 'GithubProjectProperty',
displayName: '',
projectUrlStr: 'https://myServer/myOrg/myRepo'
])
}
ERROR: The ‘properties’ section has been renamed as of version 0.8. Use ‘options’ instead
2) Remove the properties keyword but leave the option in the options block
options {
// Set the URL for the GitHub project option
[
$class: 'GithubProjectProperty',
displayName: '',
projectUrlStr: 'https://myServer/myOrg/myRepo'
]
}
ERROR: Options cannot be defined as maps
3) Treat the GitHubProjectProperty as if it can be instantiated (like office365ConnectorWebhooks)
options {
// Set the URL for the GitHub project option
GithubProjectProperty('https://myServer/myOrg/myRepo')
}
ERROR: Invalid option type "GithubProjectProperty". Valid option types: [authorizationMatrix, buildDiscarder, catchError, checkoutToSubdirectory, disableConcurrentBuilds, disableResume, durabilityHint, newContainerPerStage, office365ConnectorWebhooks, overrideIndexTriggers, parallelsAlwaysFailFast, preserveStashes, quietPeriod, rateLimitBuilds, retry, script, skipDefaultCheckout, skipStagesAfterUnstable, timeout, waitUntil, warnError, withContext, withCredentials, withEnv, ws]
4) Treat the GitHubProjectProperty as if it can be instantiated but inside a script block (because script is supposed to be valid according to attempt #3)
options {
script {
// Set the URL for the GitHub project option
GithubProjectProperty('https://myServer/myOrg/myRepo')
}
}
ERROR: Options definitions cannot have blocks
The office-365-connector-plugin is a working plugin that is supported in the options block of a Jenkinsfile. I compared its code with the github-plugin source on GitHub and noticed the following line:
#Extension
public static final class DescriptorImpl extends JobPropertyDescriptor {
The code is lacking a #Symbol directive that the office365ConnectorWebhooks appears to provide in its code:
#Extension
#Symbol("office365ConnectorWebhooks")
public final class WebhookJobPropertyDescriptor extends JobPropertyDescriptor {
Is there some special syntax to use to add the GitHub URL to a multibranch pipeline or does that plugin just not support managing it through a Jenkinsfile?
The ability to specify options in a pipeline using a Jenkinsfile requires a Symbol. There is a proposed fix in the Jenkins github-plugin that adds the necessary Symbol directive but it is not currently part of the plugin as of version 1.30.0.
See: https://issues.jenkins-ci.org/browse/JENKINS-62339
It's possible for a developer to build their own updated plugin in the meantime by updating the following file:
src/main/java/com/coravy/hudson/plugins/github/GithubProjectProperty.java in the source found at: https://github.com/jenkinsci/github-plugin
Add the Symbol:
import org.jenkinsci.Symbol;
...
#Extension
#Symbol("githubProjectProperty")
public static final class DescriptorImpl extends JobPropertyDescriptor {
...
And for good measure, make sure the code specifies the correct function signature for newInstance:
#Override
public JobProperty<?> newInstance(#Nonnull StaplerRequest req, JSONObject formData)
throws Descriptor.FormException {
The updated plugin may be installed by a Jenkins admin using the Advanced option in the Plugin Manager to upload an .hpi file from outside the central plugin repository
I had the same problem and was able to solve it with:
options{
githubProjectProperty(displayName: '', projectUrlStr: 'your_project_url')
}
I am attempting to move from a Freestyle Project to a multibranch pipeline build. I would like my Jenkinsfile to trigger when a new container has been pushed to my Quay.io repository. In the Freestyle Project I'm able to accomplish this with the Quay.io Trigger Plugin.
Moving to the Multibranch build pipeline I've found this post, that describes how to trigger on a dockerhub trigger. I've also used the Jenkins Pipeline Syntax "wizard" to generate the code to add to my Jenkinsfile:
properties([[$class: 'ScannerJobProperty', doNotScan: false], [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false], [$class: 'ThrottleJobProperty', categories: [], limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0, maxConcurrentTotal: 0, paramsToUseForLimit: '', throttleEnabled: false, throttleOption: 'project'], pipelineTriggers([[$class: 'QuayIoTrigger', repositories: ['hostedsparkbots/janitorbot-timer', 'hostedsparkbots/janitorbot', 'hostedsparkbots/sparky']]])])
In the above case when I do a scan of my github repository I get a wall of backtraces from the jenkins console:
java.lang.IllegalArgumentException: java.lang.ClassCastException#712ddbf9
at sun.reflect.GeneratedMethodAccessor4447.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jenkinsci.plugins.structs.describable.Setter$1.set(Setter.java:33)
at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:338)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:261)
Caused: java.lang.IllegalArgumentException: Could not instantiate {repositories=[hostedsparkbots/janitorbot-timer, hostedsparkbots/janitorbot, hostedsparkbots/sparky]} for QuayIoTrigger(repositories?: String[])
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:264)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:380)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:461)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:365)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:318)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:259)
Caused: java.lang.IllegalArgumentException: Could not instantiate {triggers=[{$class=QuayIoTrigger, repositories=
Does anybody actually have this working in a Jenkinsfile?
The answer:
If you cast the collection of repositories as a java.util.Set in the Jenkinsfile, this works as expected. Using your list above, you'd want to do this:
#!groovy
#import java.util.Set // this may not be required?
properties([
pipelineTriggers([[
$class: 'QuayIoTrigger',
repositories: (['hostedsparkbots/janitorbot-timer',
'hostedsparkbots/janitorbot',
'hostedsparkbots/sparky'] as Set)
]])
])
The background:
I had been struggling to figure this out myself, but ultimately dug through the source code in the Quay.io Trigger Plugin. The current plugin isn't designed with Jenkins Pipeline in mind, so it uses a Set in the constructor for the repository collection.
This is where the cast exception is occurring, as Groovy is treating the list of strings as an array, an not able automatically cast this into a Set.
By explicitly creating the list of repositories as a Set, the plugin is configurable in the Jenkinsfile.
Hope this helps!
I have some groovy script for generating jenkins jobs, which worked great.
But after reinstallation of jenkins this script throws exception.
problem part of script is:
publishers {
allure(['path-to/reports'])
}
And error is:
Processing DSL script seed.groovy
ERROR: (JobBuilder.groovy, line 55) No signature of method:
javaposse.jobdsl.dsl.helpers.publisher.PublisherContext.allure() is
applicable for argument types: (java.util.ArrayList) values:
[[PyUIAutotest/reports]]
Possible solutions: mailer(java.lang.String),
use([Ljava.lang.Object;), asType(java.lang.Class)
Finished: FAILURE
It fails on wrong signature of method, but it is correct, and i don't know what is wrong.
example of script available on wiki dock. and javadoc for allure() method
Jenkins ver. 2.46.2; Job DSL ver. 1.63, Allure-Jenkins-Plugin ver. 2.15
weird thing in that, i have another server with same plugin versions, and it works fine
Instead of
publishers {
allure(['path-to/reports'])
}
use this syntax (which you can also generate using Jenkins pipeline-syntax generator):
allure([includeProperties: false, jdk: '', properties: [], reportBuildPolicy: 'ALWAYS', results: [[path: 'path-to/reports']]])
You might find my answer here useful: https://stackoverflow.com/a/71082002/1169433
In short, you may need to add the allure-jenkins-plugin in your build dependencies.
I am trying to set build parameter (String and password param) from the Jenkinsfile but I am getting following error and the build fails.
Caused by: java.lang.UnsupportedOperationException: PasswordParameterDefinition as a class hudson.model.ParameterDefinition could mean either hudson.model.PasswordParameterDefinition or com.michelin.cio.hudson.plugins.passwordparam.PasswordParameterDefinition
at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:419)
Copy/pasted from https://issues.jenkins-ci.org/browse/JENKINS-18141:
In the example above, the DSL tries to find a subclass of hudson.model.ParameterDefinition named PasswordParameterDefinition. In your installation there are two classes named PasswordParameterDefinition, one defined by Jenkins itself and one provided by the Mask Passwords Plugin. The DSL can't decide which to use, so it generates the error.
If you have installed the Mask Passwords Plugin, you can use nonStoredPasswordParam to create a password parameter:
https://jenkinsci.github.io/job-dsl-plugin/#path/job-parameters-nonStoredPasswordParam
If you are calling your class as:
[$class: 'PasswordParameterDefinition', defaultValue: '', description: 'Vpn password', name: 'Psw']
try with this:
[$class: 'hudson.model.PasswordParameterDefinition', defaultValue: '', description: 'Vpn password', name: 'Psw']