jenkins - Jenkins2.0 pipeline script reject date arithmetic

I have the following code in groovy Jenkinsfile:def current = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss.SSSZ').parse(currenttime.trim())println currentdef end_date = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss.SSSZ').parse(scheduled_end_date.trim())println end_dateschedule_grace_period_validity = current - end_date > 5 ? false : truethe output for this is : Tue Feb 27 13:20:54 EST 2018[Pipeline] echoMon Dec 18 18:00:00 EST 2017[Pipeline] echoorg.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use stat...Read more

github - Jenkins - Gitlab Integration Issue

I am trying to integrate Jenkins ver. 2.89.4 with Gitlab 1.5.3I have entered my Gitlab host URL and API Token for accessing Gitlab.But, when I click test connection, i get the following exception trace:Any help will be no client-builder found that supports server at at com.dabsquared.gitlabjenkins.gitlab.api.impl.AutodetectingGitLabClient.autodetectOrDie( at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.jav...Read more

jenkins - Getting FATAL: No signature of method: error

I am trying to execute below commands in Jenkins groovy script. import hudson.model.*def buildA = build("Master-Build")println(buildA.getProject().getLastSuccessfulBuild()) and I am getting below errors 00:00:00.652 FATAL: No signature of method: is applicable for argument types: (java.lang.String) values: [Master-Build] 00:00:00.652 Possible solutions: wait(), save(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure) 00:00:00.652 groovy.lang.MissingMethodException: No s...Read more

jenkins - Groovy parameters are not visible in shell part of a Jenkinsfile

I'm facing a problem in Groovy script wherein the variable is not accessible in shell script part.script-1: def a=20; println ("a is: $a");output-1:a is: 20script-2:def a=20;println ("a is: $a");sh '''echo a is $a''';Output-2: groovy.lang.MissingMethodException: No signature of method: is applicable for argument types: (java.lang.String) values: [echo a is $a] Possible solutions: use([Ljava.lang.Object;), is(java.lang.Object), run(), run(), any(), with(groovy.lang.Closure) at can i get $a = 2...Read more

Read .txt file from workspace groovy script in Jenkins

I am new to Jenkins and to groovy scripting, I want to read a .txt file which is located in the workspace of one of the jobs. I am trying to do this way:myfile = Jenkins.instance.getJob('JobName').workspace.readFileFromWorkspace('file.txt');But leads to the following error: groovy.lang.MissingMethodException: No signature of method: hudson.FilePath.readFileFromWorkspace() is applicable for argument types: (java.lang.String) values: [file.txt]...Read more

How to add build parameters to jenkins multibranch pipeline?

I would like to add additional build parameters to my jenkins mutibranch pipeline job.Relevant versions:org.jenkins-ci.plugins:script-security:1.19org.kohsuke:groovy-sandbox:1.10org.jenkins-ci.main:jenkins-war:2.0 org.jenkins-ci.plugins.workflow:workflow-aggregator:2.0My Jenkins file:As you can see the first four lines are supposed to add the build parameter option.import hudson.model.*def build = Thread.currentThread().executable;build.addAction(new ParametersAction(new StringParameterValue("SVN_UPSTREAM", build.getEnvVars()['SVN_REVISION'])...Read more

groovy - How to execute SQL statement in Pipeline script of Jenkins?

I have created on pipeline and I want to execute one sql query in it. I have written following statements(Only two Lines of code, no imports/Class etc.) and throws error while executing it.import groovy.sql.Sqldef sql = Sql.newInstance("jdbc:mysql://myIP:3306/dbName", "uname","password", "com.mysql.jdbc.Driver")sql.execute "select count(*) from TableName"I am getting this errororg.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod groovy.sql.Sql newInstance java.lang.String java.lang.Stri...Read more

groovy - Jenkins pipeline Script to create build output directory

I am using Jenkins version - v2.73.2 and Jenkins pipeline - 2.5 and i have a scenario where after build is completed the output .dll files are stored in the Jenkins Slave machine below bin path C:\jenkins\Test-Build\sample1\bin , script;C:\jenkins\Test-Build\sample2\bin , package , obj, users; C:\jenkins\Test-Build\sample3\bin, common, views; C:\jenkins\Test-Build\sample4\bin, properties, fonts etc...Read more

groovy - Jenkins pipeline throws reporting:org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException

Jenkins pipeline throws reporting:org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.util.XmlSlurper parseText java.lang.StringHere is the code:def testsuites = new XmlSlurper().parseText(xml)Also I could not see this method in ScriptApproval. How can we whitelist this method manually or any other solution to fix this?...Read more

Setting up taints on pod template in Kubernetes Plugin on Jenkins

I would like to apply the tolerations on the Jenkins slave pod that are dynamically spinned by the Kubernetes Plugin. I see that the Kubernetes Plugin does not provide any option on the Jenkins UI to add the tolerations, as shown in the image below. Could anyone tell me, how can I add the tolerations in this case to the slave pods(which are generated by kubernetes plugin). P.S.:- I do not want to use labels,I Strictly want to use tolerations. And I am not sure if I want to add the podTemplate in the Jenkinsfile and specify the tolerations in th...Read more

Manipulating Jenkins Plugin Settings from Command-Line

I have a Jenkins machine that gets deployed via a provided VM. I need to add a plugin and then set the settings via a script.To install the plugin (thinBackup, fwiw), I wget the plugin as a .hpi, drop it to the plugins directory, and restart the Jenkins service (the plugin has no dependencies, so I don't need to worry further about that).Now I need to set the plugin settings' values. I can't find any documentation as to where these settings would be found. Where would that settings file be located, and is there a better way other than brute for...Read more

jenkins - Check if a downstream job is enabled before triggering it

I have a job (JobA) which, upon success, builds JobB. The Jenkinsfile for JobA contains a post section like this:post { success { build job: 'JobB', wait: false }}The problem is that when JobB is disabled, JobA will fail no matter what with the following message:ERROR: Failed to trigger build of JobBFinished: FAILURECan I prevent JobA from failing when JobB is disabled while still using declarative syntax?...Read more