-
-
Save chinshr/aa87da01ec28335e3ffd to your computer and use it in GitHub Desktop.
#!groovy | |
# Best of Jenkinsfile | |
# `Jenkinsfile` is a groovy script DSL for defining CI/CD workflows for Jenkins | |
node { | |
} |
# Jenkinsfile | |
# Build and test a Maven project | |
node { | |
git url: 'https://github.com/user/repo.git' | |
def mvnHome = tool 'M3' | |
sh "${mvnHome}/bin/mvn -B -Dmaven.test.failure.ignore verify" | |
step([$class: 'JUnitResultArchiver', testResults: | |
'**/target/foobar/TEST-*.xml']) | |
} |
# Jenkinsfile | |
# Verify a Maven project | |
node { | |
git url: 'https://github.com/user/repo.git' | |
def mvnHome = tool 'M3' | |
sh "${mvnHome}/bin/mvn -B verify" | |
} |
stage "unit test" | |
node { | |
git "[email protected]:michaelneale/oaks-trail-ride.git" | |
sh "echo unit test app" | |
} | |
stage "test on supported OSes" | |
parallel ( | |
windows: { node { | |
sh "echo building on windows now" | |
}}, | |
mac: { node { | |
sh "echo building on mac now" | |
}} |
node { | |
for (int i=0; i< 2; ++i) { | |
stage "Stage #"+i | |
print 'Hello, world $i!' | |
} | |
stage "Stage Parallel" | |
def branches = [:] | |
for (int i = 0; i < numHelloMessages.toInteger(); i++) { | |
branches["split${i}"] = { | |
stage "Stage parallel- #"+i | |
node('remote') { | |
echo 'Starting sleep' | |
sleep 10 | |
echo 'Finished sleep' | |
} | |
} | |
} | |
parallel branches | |
} |
@Headcult Dockerfiles can be run at the command line with a "docker build" command, but the Jenkinsfiles are not executed in this manner
When you commit and push your Jenkinsfile to your git repo (assuming you are using git, jenkins and the git plugin) then the Jenkins slave(s) will execute the steps in the Jenkinsfile for you. You will need to have configured a job pointing to the git repo and watching for changes first. Look at the Folders plugin and run Folder Computation in Jenkins - this will create a job for every branch which has a Jenkinsfile present in your repo, it's very useful!
(bonus tip: You can even setup your Jenkinsfile to run your docker build)
For the parallel case, reading the docs from Jenkins from "Jobs in Parallel," you should use:
node {
for (int i=0; i< 2; ++i) {
stage "Stage #"+i
print 'Hello, world $i!'
}
stage "Stage Parallel"
def branches = [:]
for (int i = 0; i < numHelloMessages.toInteger(); i++) {
def index = i
branches["split${i}"] = {
stage "Stage parallel- #"+index
node('remote') {
echo 'Starting sleep'
sleep 10
echo 'Finished sleep'
}
}
}
parallel branches
}
This will solve the issue of having i=4
for each iteration of the parallel loop.
Can you someone please help , That how can i deploy my 8 build artifact into the env server simultaneously via jenkins jobs through Deployit tool
Can anyone answer whether the examples with iteration actually work? JENKINS-26481 and this stack overflow indicate that loops of all kinds are broken
Hi guys, Can you give an example to pass parameters from one job to another job? (Pipeline project)
I have been stuck with this for a while now, kindly provide suggestions.
I'm trying the below, which did not work for me:(
Project Name: test2
node() {
stage 'pass params'
paramAValue = "paramAValue"
paramBValue = "paramBValue"
build job: 'test3', parameters: [[$class: 'StringParameterValue', name: 'ParamA', value: paramAValue], [$class: 'StringParameterValue', name: 'ParamB', value: paramBValue]]
}
Project Name: test3
node() {
stage 'retrieve params'
print "${env.paramA}"
}
stage ('pass params') {
def paramAValue = "paramAValue"
...
}
etc.
Also try:
echo paramA not print "${env.paramA}"
The preferred method of getting job parameters is to use the "params" map.
So use echo params.paramA
Can someone please give an example of jenkins file which shows how to connect to jenkins slave and execute the shell scripts and python scripts residing in jenkins slave itself.
Are you asking how to run the Jenkinsfile on a local machine without jenkins?