Step one: global tool config to add git excutable
- Go to Dashboard
- Click Manage Jenkins
- Click Global Tool Configuration
- In Git Section add git executable path. For me: /usr/bin/git
- Click apply
Step two: Create a new item
- Go to Dashboard
- Click New Item
- Give name
- Click Pipeline
- Click OK
- In Pipeline Section, select Pipeline Script from SCM from drop down for Definition field
- Choose Git from dropdown for SCM
- Pu file:///home/leo2019/play_jenkins in repository Url field
- Click apply
Step three: Create a Jenkinsfile
In the root directory of git repository, create a file called Jenkinsfile. For this example, the file is put in /home/leo2019/play_jenkins/
The following is the content of my test Jenkinsfile
#!/usr/bin/env groovy
pipeline {
agent any
stages {
stage('Stage 1') {
steps {
echo 'Hello world!'
println "Great!"
sleep(30)
}
}
}
}
Step four: build
Some console output
Started by user unknown or anonymous
Obtained Jenkinsfile from git file:///home/leo2019/play_jenkins
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/My test for blog
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
No credentials specified
Cloning the remote Git repository
Cloning repository file:///home/leo2019/play_jenkins
> /usr/bin/git init /var/lib/jenkins/workspace/My test for blog # timeout=10
Fetching upstream changes from file:///home/leo2019/play_jenkins
> /usr/bin/git --version # timeout=10
> git --version # 'git version 2.17.1'
> /usr/bin/git fetch --tags --progress -- file:///home/leo2019/play_jenkins +refs/heads/*:refs/remotes/origin/* # timeout=10
> /usr/bin/git config remote.origin.url file:///home/leo2019/play_jenkins # timeout=10
> /usr/bin/git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
> /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 743c558e082f3fe9944db4ecd969f6ffc007aaeb (refs/remotes/origin/master)
> /usr/bin/git config core.sparsecheckout # timeout=10
> /usr/bin/git checkout -f 743c558e082f3fe9944db4ecd969f6ffc007aaeb # timeout=10
Commit message: "greate"
First time build. Skipping changelog.
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Stage 1)
[Pipeline] echo
Hello world!
[Pipeline] echo
Great!
[Pipeline] sleep
Sleeping for 30 sec
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS