Specify Git Tool to use in Multi-OS Agent Jenkins Environment for Declarative Pipeline
Do not use the approach of specifying 2 git configurations. Otherwise, you have to change every job. Just have one configuration and override the tool location at the agent/ node level. Only specify different tools where the variant matters. In your pipeline you'd reference :
tools {
jdk 'jdk1.8'
}
Global configuration
Node Configuration
The Tools selector is intended to choose flavors of tools (jdk ver, openjdk vs oraclejdk, etc.). You override the tool location at the node level. My complete example was JDK, since versions matter, but also win/linux location differ. Git is just git.
Jenkins : Global Tool Configuration - setup differs based on agent
Found that in each node, and menu "Node Properties" there is an option "Tool Locations" that allows me to override the tools default location.
How can I build Jenkins Projects with a custom JDK?
You can use the desired JDK with a docker agent.
With this, you can defined an image which use the appropriate JDK or any image.
For exemple, in your case, you can have the JDK 11 for jenkins itself and the one you want in each job. Exemple with openjdk :
pipeline {
agent {
docker { image 'openjdk:11' }
}
stages {
stage('Test java version') {
steps {
sh 'java -version'
}
}
}
}
You can choose the tag you want to select the appropriate version.
You just need to setup docker in your jenkins instance.
Using a Jenkins pipeline to checkout multiple git repos into same job
You can use the dir
command to execute a pipeline step in a subdirectory:
node('ATLAS && Linux') {
dir('CalibrationResults') {
git url: 'https://github.com/AtlasBID/CalibrationResults.git'
}
dir('Combination') {
git url: 'https://github.com/AtlasBID/Combination.git'
}
dir('CombinationBuilder') {
git url: 'https://github.com/AtlasBID/CombinationBuilder.git'
}
sh('ls')
sh('. CombinationBuilder/build.sh')
}
Is it possible to Git merge / push using Jenkins pipeline
It is not possible at the moment because GitPublisher
plugin, the plugin previously responsible for tagging/merging/pushing in freestyle jobs, has not been updated to be compatible with Jenkins pipelines. You can follow that issue on both the pipeline plugins compatibility page and the dedicated GitPublisher Jira issue.
So it seems the only option you have is to actually shell out your tag/merge commands... However, note that you can still benefit from some Jenkins built-in capabilities such as the use of credentials for your Git repo, which make it pretty straightforward to then tag / merge following your needs.
Example check-out :
git url: "ssh://jenkins@your-git-repo:12345/your-git-project.git",
credentialsId: 'jenkins_ssh_key',
branch: develop
Then the tag / merge / push will be pretty straightforward :
sh 'git tag -a tagName -m "Your tag comment"'
sh 'git merge develop'
sh 'git commit -am "Merged develop branch to master'
sh "git push origin master"
I hope that one day GitPublisher will be released in a pipeline-compatible version, but for now this workaround should do.
Jenkins declarative pipeline: How to access value of parameter when it has spaces in its name?
Update: It turns out that params['Force generate NuGet']
actually does work. I had a long Jenkinsfile with some legacy code that overwrote the global variable params
. That is why it was not working for me. I revised the legacy code, and now I can get the parameters.
Jenkins pipeline environment variables
Please note that only when you run the pipeline code in MultiBranch Project you would be able to fetch the branch name environment variable. The documentation from Jenkins is as follows:
BRANCH_NAME
For a multi branch project, this will be set to the name of the branch being built, for example in case you wish to deploy to production from master but not from feature branches; if corresponding to some kind of change request, the name is generally arbitrary (refer to CHANGE_ID and CHANGE_TARGET).
So, you can use the environment variable only in a MultiBranch Pipeline Project. you can retrieve it in multi branch project using the below variable:
"${env.BRANCH_NAME}"
Related Topics
Print a File in Multiple Columns Based on Delimiter
Build a Linux Module Without Source Code
How to Compile This Asm Code Under Linux with Nasm and Gcc
How to Format a String in Bash Shell
How to Automate Measuring of Bandwidth Usage Between Two Hosts
Cmake Test for Processor Feature
Use Grep to Find the Words That Have Two 'S' Separated by a Space
Native Linux App to Edit Win32 Pe Like Reshacker
Sort Entries of Lines Using Shell
Shell Script: Hexadecimal Loop
How to Use the Parallel Command to Exploit Multi-Core Parallelism on My MACbook
Delete Repeated Characters Without Back-Referencing with Sed
Segmentation Fault with a Variable in Section .Data
Why Does Script Not Recognize File Extension
Using Ssh to Run a Cleartool Command with Agruments on Remote a Linux MAChine
How to Change the Permissions in Openshift Container Platform