How to add build server details in Jenkins pipeline? - jenkins

I am having Jenkins in one server and my build server is different. How to point build server in Jenkins pipeline so that my application will build in build server
Using grade and java.
Do we need to use node('Build 1') inside stage?
Suggest me some sample code please.

In Jenkins, your build server called slave machine or Jenkins nodes, which you need
Firstly add this "buildserver" into Jenkins nodes in advance, then you will get node name (or label them like ubuntu-buildserver), see one jenkins distributed build blog
Secondly in scripted pipeline you specify/reference this name in node
node("ubuntu-buildserver")
If you use declarative pipeline, check syntax#agent part.
It is similar for other global configuration like credentialsId, you need define those parameters in jenkins and refer to use them in your pipeline script.

Related

Chef deployment using Declarative Pipeline

I would like to create a declarative Jenkins pipeline setup for the continues integration and Deployment, My only confusion was how Jenkins and chef are going to communicate in this process, after the continue integration, I want the chef to take over and install the Jar or Zip packages and deploy them on the several nodes from Jfrog Repo. Here maven is my build tool. In Jenkins pipeline I can setup until the build is done , is there any thing that I can do in the Post section of the pipeline for the chef communication for deployment or it has to be done. Please share some suggestion.
You can achieve this by putting workstation in one of the jenkins node.
Check out the below image for the same, instead of Ansible use Chef. I suppose this might work, haven't use chef recently.
Link: https://thenucleargeeks.com/2020/06/07/jenkins-openshift-pipeline/

Jenkins Build Multiple projects in same repository

Previously we had a single monolith in GitLab repository and we used to build project in Jenkins using Jenkinsfile.
Now we are migrating it into multiple microservices and all reside in same GitLab repository. Is it possible to create pipelines for this type of setup or do we need to have each microservice in separate repository. If it is possible please point me to appropriate resources.
Each microservice can have its own Jenkinsfile, you have to tell to the Jenkins job the path of the Jenkinsfile if it is not located at the root path.
In your pipeline configuration job choose "Pipeline script from SCM" and set the "Script Path".
To only checkout the microservice you need, you can use in the "SCM" then "Additional Behaviours" the "Check out to a sub-directory" (then if the Jenkinsfile is now at the pseudo root path, you won't need to change the default "Script Path").
Yes it is possible to create pipelines to build/test/deploy from a single repository.
Use Declarative Pipeline in Jenkins.
You can have your microservices separated in different directories in a single repo and can build them all using a single pipeline using the stages & dir() option in Jenkinsfile. We're building close to 15 components from a single pipeline and push it to it's relevant artifactory from the same job. You can build non-dependent microservice components parallely too.
Documentation --> Jenkins Pipeline,Jenkinsfile

How to set in Jenkins a credential id for Perforce SCM before starting the job in a slave node?

Let me explain what I have before exposing my question. I have a Jenkins with a seed project that creates jobs from groovy scripts using the Job DSL plugin.
I have a job that uses Perforce as SCM. This has been setup from the groovy and the Perforce credentials have been also set using the id passed to credential() inside scm{perforce{credential("perforce1")}}
This job is configured for running only in my slave nodes.
What I want to do is: I would like the slave node, before the SCM step, sets the credentials for Perforce based in something like environment variable (ex: NODE_SCM) so when launch the build process, the node would set the credentials for using it before the Perforce SCM starts the process.
The credentials for Perforce is now in Jenkins but could be created in runtime or something like that if it is possible what I want to do.
Example: Imagine I have two credentials stored in my Jenkins (perforce1 and perforce2). The variable NODE_SCM would be one of those ids and set it for building the job in the slave node.
I donĀ“t know if I explain correctly what I want to achieve.
Thanks for your attention in advance.
Best regards

Jenkins 2.x Slave-Agent Variables in Pipelines

I have tried every permutation that I can find to pull a pre-existing variable from a specific Jenkins Slave and I cannot find a solution.
We have a git branch variable defined on each slave agent as a default branch for all builds initiated on that slave. This is to ensure that all DSL scripted job config is tested on our dev machine before it is promoted to a higher jenkins environment.
I have created a pipeline that will build all the components needed to stand up a new jenkins (with all of our enterprise deployment pipelines created) and it needs access to that one specific variable to correctly build the jobs based on the jenkins master/slave combo that it is running on.
I need a way (in a jenkinsfile) to access the variables that are configured on a particular jenkins slave machine.

Output sonarqube result to different server locations

Is there a way to output SonarQube results to 2 different server locations through a Jenkins configuration, using a single Jenkins build for each SonarQube output?
I know Jenkins has a concept of parameterized build where the build could be parameterized by the Sonar Server name.
I guess that you are talking about the parameterized plugin:
https://wiki.jenkins.io/display/JENKINS/Parameterized+Trigger+Plugin
This plugin let you provide data when you trigger the build. This is a great plugin when your builds trigger each others, and you need data from a previous build executed on another slave.
If you want a single build, and the Sonar Server Name is determined inside the build, you will need to find your way using Shell.
Get it at some point:
SONAR_NAME=$( .... )
and re-use it within the same build:
ssh $SONAR_NAME#....

Resources