groovy

JobDSL - Create a new job if it doesn't exist in Jenkins already

对着背影说爱祢 提交于 2021-01-27 19:00:06
问题 I created this Groovy JobDSLs script to generate a new Jenkins jobs. List screen = [["AAA", "Description" ],["AAA", "Description" ]] for (item in screen) { job(item[0]) { description(item[1]) steps { shell('command ...') } }​ }​ Is there a way how to tell JobDSL plugin to not create a job in the List, if it already exists in Jenkins? I don't want to keep to separate files for generating new jobs. One file for new jobs and one file for all existing jobs. 回答1: If a job definition does not

Detecting copied or similar text blocks

时光总嘲笑我的痴心妄想 提交于 2021-01-27 13:43:03
问题 I have a bunch of texts about programming in Markdown format. There is a build process that is capable of converting those texts into Word/HTML and also perform simple validation rules like spell checking or checking if document has required header structure. I would like to extend that build code to also check for copy-pasted or similar chunks within all texts. Is there any existing Java/Groovy library that can help me with that analysis? My first idea was to use PMD's CopyPasteDetector, but

Jenkins declarative pipeline throws org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified getAt method

戏子无情 提交于 2021-01-27 12:44:37
问题 I have defined a shared library in Jenkins: import com.codependent.jenkins.pipelines.Utils def call(List<String> mavenGoals){ def processedMavenGoals = mavenGoals.join ' ' pipeline { agent any ... } If i call this from my project's Jenkinsfile like this it works ok: #!groovy @Library('jenkins-pipeline-shared-library-example') _ buildPipeline(['clean', 'install']) However if I omit the parethesis as Groovy syntax allows: #!groovy @Library('jenkins-pipeline-shared-library-example') _

Modifying return value of getters of String fields

筅森魡賤 提交于 2021-01-27 12:11:13
问题 Let's say I have classes similar to domain classes in my application with some Long, Double, Date and String fields. These classes extend base class with some common fields and few common methods. Whenever I access class field (though getter) that is String, I want to make some changes to the value returned (for example remove html tags). Is there a better way than making implementations of getters for each fields of String type? What about inherited fields? 回答1: Don't change default getter

How to use multiple classes in multiple files in scripts?

a 夏天 提交于 2021-01-27 11:45:26
问题 I need to make a standalone Groovy script that does not require compilation and runs without Groovy installed. It works well, but it fails to recognize any other script than the main script. My folder structure is the following: libs\ groovy-all-2.4.3.jar ivy-2.4.0.jar src\ makeRelease.groovy ReleaseHelper.groovy I am launching the script this way from the src folder: java -cp "../libs/*" makeRelease.groovy makeRelease looks like this: public class makeRelease { public static void main(String

Cannot execute Groovy Maven Plugin as a goal

天大地大妈咪最大 提交于 2021-01-27 07:46:38
问题 I am using Apache Maven 3.3.9 with the Groovy Maven plugin. Here is the relevant section of the pom.xml (the inlined Groovy script is just fictional): <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>groovy-maven-plugin</artifactId> <version>2.0</version> <executions> <execution> <id>myGroovyPlugin</id> <phase>prepare-package</phase> <goals> <goal>execute</goal> </goals> <configuration> <source> log.info('Test message: {}', 'Hello, World!') </source> </configuration> </execution> <

How to set up cron to run once a day at random times

ぐ巨炮叔叔 提交于 2021-01-27 07:12:38
问题 Hi so right now I have a basic cron that runs my stuff twice a day at 1 and 6. Something like: H 1,18 * * * The problem is I have like 100 things kicking off at this time which is clogging up my machine. I want to randomly generate a time once a day for each job to run. It's ok if 5-7 are going at once. So I guess my question is. For one is this possible? If so is there a best practice for this? I'm loading everything up in groovy so I was just thinking about generating a number between 1-24

Groovy currency formatting

微笑、不失礼 提交于 2021-01-27 05:45:43
问题 I'm writing some rows to a text file using groovy (grails 1.3.7) and I want to format the currency like this example output: $100,000,000.00 $9,123,123.25 $10.20 $1,907.23 So basically right-justified, or left padded, with the dollar sign in front of the number so they all line up like the above. The first number is the longest we would expect to see. Right now I have an amount variable that is simply defined with a def and not string or number or anything specific like that but I can

Using GroovyShell as “expression evaluator/engine” (or: How to reuse GroovyShell)

≯℡__Kan透↙ 提交于 2021-01-27 02:55:26
问题 I'm using GroovyShell as an "expression evaluator/engine" inside my program. It accepts two inputs: (a) one or more init scripts (b) user-defined script. Both are then concatenated at runtime as big chunk of script (text) and feed to the shell. String initScripts = getFromDB() String userScript = getFromUser() def shell = new GroovyShell() output = shell.evaluate(initScripts + userScript) The above code will run in a loop, where the contents of userScript will vary. So far, initScripts only

How to disable error highlighting in VS Code?

 ̄綄美尐妖づ 提交于 2021-01-26 21:55:22
问题 I need to disable error highlighting in Java files in VS Code. VS Code tries to check a Groovy file while thinking it is a Java file. As you can see in the picture all imports after the first and the types after the first field are highlighted red (due to missing semicolons). However I do not want the error check for this Groovy file. NOTE: I only have the plugins Clang, RedHat.Java, Markdown PDF, Sort Lines, and Uncrustify installed. Even if I disable all the red highlighting is visible. 回答1