Jenkins 2 pipeline deploying to udeploy - jenkins

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.

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"');

Does a Jenkins plugin exist that adds stage dependency to a pipeline, similar to how Gradle has dependsOn(), doFirst(), doLast() etc

I would like to have stages depend on each other to run in a Jenkins pipeline. Ideally I would be able to define the stages in any order within the pipeline, but have them execute according to their dependencies. A simple example being if my 'test' stage depends on the 'build' stage to run but I have 'test' defined first in the pipeline, the pipeline would recognize this and run 'build' before 'test'.
I've looked at a lot of plugins for Jenkins but haven't come across any that deal with stage dependence. I'm relatively new to Jenkins so I may just be looking in the wrong places. So if anybody knows if something like this exists already please let me know. If this doesn't exist already is it something that I could create by making my own Jenkins plugin? Or would this change something fundamental to how Jenkins pipelines work?

Jenkins pipeline run gradle tasks within sshagent

I'm creating a jenkins pipeline which utilizes a build.gradle script to build the project.
One of the first things gradle does is check out some git repos, I need to run this with ssh, so I thought I could wrap the code in sshagent like this:
sshagent(['c6f7cd1b-9bb3-4b33-9db0-cbd1f62cd0ba']){
sh 'git clone git#Repo.git'
}
the Id is mapped to a global jenkins credential with the private key in it, I also use it in another pipeline to tag a repo and push it to master, using the same credentialId.
However I get following output when trying to run the pipeline:
FATAL: [ssh-agent] Could not find specified credentials
I have no idea why I get this, when I'm using a copy paste from the other pipeline.
Anyone who can point me towards the right direction?
Thx

Jenkins Shared Libraries context

I have a pipeline job which loads Jenkinsfile from git repository. My Jenkinsfile looks like this:
#!groovy
#Library('global-utils-lib') _
node("mvn") {
stage('build') {
checkout scm
}
stage('merge-request'){
mergeRequest()
}
}
global-utils-lib is shared library loaded in Global Pipeline Libraries from another git repo with following structure
vars/mergeRequest.groovy
mergeRequest.groovy:
def call() {
sh "ip addr"
def workspacePath = env.WORKSPACE
new File(workspacePath + "/file.txt").text
}
Job is run against docker container (docker plugin).
When I run this job then docker container is provisioned correctly and scm is downloaded but I get FileNotFoundException.
It looks like code from shared library is executed against jenkins master not slave:
presented IP comes from master
file is loaded correctly when I pass correct path to the scm on master
How can I run library code against slave? What I am missing?
It's generally not a good idea to try and do things like new File() instead of using existing Pipeline steps.
Your Pipeline script is interpreted and executed by the Jenkins master so, as you're seeing, the attempt to use the File API doesn't work as you might expect.
Sticking to Pipeline steps helps ensure that your pipeline is durable (i.e. survives restarts), is pausable, and doesn't block the execution thread, preventing parallel steps from working, for example.
In this case, the existing readFile step can be used.
I don't know how well the Docker Plugin interacts with Pipeline (though I imagine it should be transparent), and without knowing which agents have the "mvn" label, or whether you can reproduce this outside of a shared library, it's unclear why your sh step would appear to be running on the master.
The Docker Pipeline Plugin is explicitly designed for Pipeline, so it might give better results.

Jenkins how to create pipeline manual step

Prior Jenkins2 I was using Build Pipeline Plugin to build and manually deploy application to server.
Old configuration:
That works great, but I want to use new Jenkins pipeline, generated from groovy script (Jenkinsfile), to create manual step.
So far I came up with input jenkins step.
Used jenkinsfile script:
node {
stage 'Checkout'
// Get some code from repository
stage 'Build'
// Run the build
}
stage 'deployment'
input 'Do you approve deployment?'
node {
//deploy things
}
But this waits for user input, noting that build is not completed. I could add timeout to input, but this won't allow me to pick/trigger a build and deploy it later on:
How can I achive same/similiar result for manual step/trigger with new jenkins-pipeline as prior with Build Pipeline Plugin?
This is a huge gap in the Jenkins Pipeline capabilities IMO. Definitely hard to provide due to the fact that a pipeline is a single job. One solution might be to "archive" the workspace as an "artifact" (tar and archive **/* as 'workspace.tar.gz'), and then have another pipeline copy the artifact and and untar it into the new workspace. This allows the second pipeline to pickup where the previous one left off. Of course there is no way to gauentee that the second pipeline cannot be executed out of turn or more than once. Which is too bad. The Delivery Pipeline Plugin really shines here. You execute a new pipeline right from the view - instead of the first job. Anyway - not much of an answer - but its the path I'm going to try.
EDIT: This plugin looks promising:
https://github.com/jenkinsci/external-workspace-manager-plugin/blob/master/doc/PIPELINE_EXAMPLES.md

Resources