I wanted to run groovy scripts in my IDE instead of Jenkins Script console. is this possible? If so where i can download http://javadoc.jenkins-ci.org/ API so that i can put that in classpath.
I cannot refer hudson.model.* and other classes with jenkins CLI jar
There is a webpage that explains how to configure Eclipse on how to Write Groovy scripts for Jenkins with code completion
Short version:
create a new maven project,
add jenkins dependencies,
update settings.xml to include jenkins repo,
add Groovy support to Eclipse(optional),
convert project to groovy and you're good to go.
BTW, for Eclipse Mars, the Groovy plugin is here: http://dist.springsource.org/snapshot/GRECLIPSE/e4.5/
Related
Earlier I was using JenkinsFile to run CI/CD pipeline in jenkins, but now we're migrating to Azure DevOps. So to build a pipeline in Azure DevOps on Mac, I'm using a Yaml file.
In jenkinsfile, I ran groovy script using the following syntax:
pipe = load ('path/to/groovy/script')
pipe.go()
,where "go()" is a function in the groovy script
But, I'm unable to configure the yaml file in similar way
What I found online was running this groovy via gradle build
I want to configure the yaml to run groovy script like in jenkinsfile, as in, without installing gradle or any third party.
Configure yaml in azure devops to run groovy script
If you are using private agent, you have to install on the agent machine:
Java 8 JDK
Apache Groovy 2.5.7 (Downloaded as zip and extracted to some local
folder)
Then set environment variables, open CMD and run these commands:
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_101"
setx /M PATH "%PATH%;C:\Program Files\Java\jdk1.8.0_101\bin"
setx GROOVY_HOME "C:\Users\<UserName>\Desktop\apache-groovy-sdk-2.5.7" (the first path is when you extracted the Apache Groovy 2.5.7)
setx /M PATH "%PATH%;C:\Users\<UserName>\Desktop\apache-groovy-sdk-2.5.7\bin" (the first path is when you extracted the Apache Groovy 2.5.7 )
Now, we could run groovy scripts without installing gradle or any third party during the building, in the build definition add Command Line Task (not Bash) and choose your groovy script:
If you are using the hosted agent, you need more steps to download and unzip task Apache Groovy 2.5.7.
Hope this helps.
I have a private repo and want to publish the build artifacts to another public repo (it's the packaged application)
How can I do that in jenkins? I could only find publish on the git I've used to build.
Thanks
There are multiple ways to do this:
- Using a shell script that calls the GIT command line tool. This can be a post-build script, the same script compiling the code, etc.
- Same thing in groovy
- Call a downstream job to do that for you (probably the best solution IMHO)
The main problem would be the GIT credentials, but that is not an big issue...
It looks like the Jenkins Scriptler plugin is no longer available, due to security reasons: https://wiki.jenkins-ci.org/display/JENKINS/Scriptler+Plugin
"Distribution of This Plugin Has Been Suspended"
Is there a similar plugin that I could use to run saved Groovy scripts?
Hi you can store your groovy scripts in Managed Files and pass the parameters to groovy script through Extended Choice Parameters Plugin.
Or else you can download Scriptler plugin source code and add it to your /var/lib/jenkins/plugin folder and start Jenkins server. It will work fine.
For removed plugins: You can find the .hpi file on archive sites on the internet, and then in Jenkins in Manage Plugins, use the "Advanced" tab > "Upload Plugin" to install it.
I use jenkins to do auto deployment weekly to a tomcat server, and it is fairly simple to do using the "curl" with the tomcat manager. and since i am only uploading a .war file, so its very straight forward.
But when comes to a backend console application, Anyone has any idea how to use jenkins to upload an entire "set of folders with files" onto a linux box? The project that i have is built via ant and has all the folder inside the SVN.
A couple things come to mind.
Probably the most straightforward thing to do is use the ant scp task to push the directory / directories up to the server. You'll need the jsch jar on your Ant classpath to make it work, but that's not too bad to deal with. See the Ant docs for the scp task here. If you want to keep your main build script clean, just make another build script that Jenkins can run named 'deploy.xml' or similar. This has the added benefit that you can use it from places other than Jenkins.
Another idea is to check them out directly on the server from SVN. Again, ant can probably help you with this if you use the sshexec task, and run the subversion task inside of that. SSHexec docs here
Finally, Jenkins has a "Publish Over SSH" plugin you might try out. I've not used it personally, but it looks promising! Right over here!
At the moment, i have Sourcetree making my branches, they will be called "feature/my-branch" and i can send that to my hg repo, and retrieve it from jenkins and build.
but, sonar does not accept "/" in the branch name, so i wanted to change "/" to "-" or something.. in a groovy script in the build phase.
Is something like that possible?
my solution so far:
parameter: BRANCH
default value: feature/my-branch
groovy scrips: def replaced = BRANCH.replaceAll(/\//, '-')
but it will not recognize my BRANCH, i've tried adding it in all sorts of ways..
any help to make my "feature/my-branch" be analyzed by sonar will be appreciated.
How are you invoking SonarQube on Jenkins? I assume it's via the SonarQube Jenkins Plugin. You could use the EnvInject Plugin to edit BRANCH. Here's an untested possibility for you to mull over:
SONAR_BRANCH=${BRANCH//\//-}
And in the SonarQube plugin's "Additional options":
sonar.branch=${env.SONAR_BRANCH}
If that won't work, or if you don't want EnvInject, you could do everything in one Execute Shell build step:
SONAR_BRANCH=${BRANCH//\//-}
mvn sonar:sonar -Dsonar.branch=${SONAR_BRANCH}