How to do Nant build using jenkinsfile for a pipeline job in Windows? - jenkins

I am changing my Freestyle Jenkins job configuration to Pipeline. I need to Invoke Nant to build a .net application. How is it performed using jenkins file?

Well, in groovy script you can use bat function to execute cmd command. So you can type something like bat '<path_to_nant> <nant_parameters>'

Related

how to execute a bash script in a jenkins declarative pipeline

I have started recently using Jenkins in windows 10. I have a freestyle job that sync from the SCM, build a C++ solution and then it runs a batch script to upload to steam. I am trying to convert it to pipeline as I realized reading the documentation how much more powerful it is. My problem is that on the step to run the .bat file it gets stuck forever, this is the step:
...
Stage('batch script'){
steps{
bat 'start C:/Users/User/.jenkins/workspace/Project/Steam Build Scripts/scripts/build_dev.bat'
}
}
...
and this is the simple .bat file:
"C:\Users\User\.jenkins\workspace\Project\Steam Build Scripts\builder\steamcmd.exe" +login "someUser" "somePassword" +run_app_build "C:\Users\User\.jenkins\workspace\Project\Steam Build Scripts\scripts\app-build-813780-dev.vdf" +quit
running the same file from the freestyle job works fine like this:
I found out the way in case somebody has the same issue, due to the path containing spaces it has to be called like this:
bat ('call "C:/Users/User/.jenkins/workspace/Project/Steam Build Scripts/scripts/build_dev.bat"');

How to start a Jenkins multibranch pipeline build from the command line (cli)?

Currently I can start a Jenkins job using the cli.
Example:
java -jar jenkins-cli.jar -s http://buildserver:8080 build Job_Name
I am playing around with the Jenkins multibranch pipeline feature and have not figured out how to start this type of job using the above command.
Any ideas how I can start a pipeline build via above cli?
On a multibranch pipeline, the job name is made of both the project name and the branch because a job is actually a build on one branch, you can see the global pipeline as just a container.
In the end, if your pipeline configuration is named your-project and you want to launch the job for the newfeature branch, you should do :
java -jar jenkins-cli.jar -s http://buildserver:8080 build your-project/newfeature
Also, the full project name is shown by Jenkins as shown above :

Passing Jenkins classpath via gradle plugin

I have a groovy script with objects which runs in my Jenkins script window. This script references my Jenkins instance and creates new Jenkins branch jobs.
The script runs in the the Jenkins script window. Now I have a requirement to use Jenkins Gradle plugin to execute the script. The groovy plugin works, but as I said the requirement is to accomplish this via the gradle plugin.
I've tried Gradle task type JavaExec, which forks a new JVM and I lose access to my Jenkins instance. I also tried Groovy evaluate(File file) method but classpath reference to Jenkins classes are lost.
// FAILS: forks a new JVM that does not have access to Jenkins object graph
task runCreateBranchJobs(type: JavaExec) {
description 'Create Branch Jobs in Jenkins'
main = 'createBranchJobs'
classpath = sourceSets.main.runtimeClasspath
}
// FAILS: has no knowledge of Jenkins classes, even when evaluated in Jenkins job
task runCreateBranchJobsInSameProcess {
doLast {
evaluate(new File("${projectDir}/src/main/groovy/createBranchJobs.groovy"))
}
}
Any suggestions on how to run the groovy script within the context of the Jenkins Job while successfully passing the classpath using the gradle plugin?

Jenkins 2 pipeline deploying to udeploy

I am creating a CI/CD pipeline. I am trying to create a groovy function in order to deploy a build to udeploy.
I know I will need to pass the parameters used in to the function such as:
udeployServer,
component,
artifactDirectory,
version,
deployApplication,
environment and
deployProcess.
I was wondering has anyone tried to implement this or has anyone any idea how I should approach this?
Thanks
I don't know anything about udeploy servers but I do know there is no pipeline plugin for udeploy, which means that you will not have a function such as :
udeploy: server=yourserver component=yourcomponent artifactDirectory=...
However Jenkins allow you to use shell commands inside your groovy pipeline, so you should be able to do pretty much everything you need. So I guess the real question is how do you usually deploy a build to udeploy ? Do you do it via a REST API, do you push a file via FTP, ... ?
Jenkins build will be pretty straightforward, have a look at how to checkout and build using Jenkins pipeline.
An example pipeline could look like :
{
stage 'Build'
def mvnHome = tool 'M3'
sh "${mvnHome}/bin/mvn clean install"
//... Some other stages as needed...
stage 'Deploy'
sh "execute sh deploy script here..."
}
... where you deploy stage could use other plugins to copy files to your server, run REST API requests, etc. While writing a pipeline, have a look at Pipeline Syntax link for a Snippet Generator giving more detailed information about existing plugins.

How to invoke Ant in Jenkins pipeline job using groovy script?

I am changing my Freestyle Jenkins job configuration to Pipeline. I need to Invoke Ant to perform LogPublisherTask and ArtifactFilePublisherTask. How is it performed using Groovy scripting?
You invoke ant just like you do it with maven (take a look at examples https://jenkins.io/doc/pipeline/jenkinsfile/):
node ('linux'){
stage 'Build and Test'
env.PATH = "${tool 'Ant'}/bin:${env.PATH}"
checkout scm
sh 'ant build'
}
The tasks themselves should be configured in the build.xml.

Resources