Create Jenkins Job in Local Environment
Have you setup the Jenkins in your local environment? If not follow my blog here https://malshani-wijekoon.medium.com/installing-jenkins-on-macos-961e5fa113b4
Once you setup the Jenkins follow below steps to create your first jenkins job
Create the first job
- Click the ‘create a job’ option. Choose an item. Here I’m using a ‘Pipeline’
2. Configure the Job
3. Add following code to pipeline script.
pipeline {
agent any
tools {
// Use the configured Maven installation (e.g., "Maven3")
maven 'Maven'
}
stages {
stage('Checkout') {
steps {
// Checkout the source code from the Bitbucket repository
script {
// Replace 'your-username' and 'your-password' with your Bitbucket credentials
withCredentials([usernamePassword(credentialsId: 'Bitbucket-Credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
checkout([$class: 'GitSCM',
branches: [[name: '*/develop']], // Replace with your desired branch
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanCheckout'], [$class: 'CloneOption', depth: 1, noTags: false, reference: '', shallow: true, timeout: 120]],
userRemoteConfigs: [[
credentialsId: 'Bitbucket-Credentials', // Replace with your Bitbucket credentials ID
url: 'https://MalshaniW@bitbucket.org/MalshaniW/dbmigration_flyway.git' // Replace with your Bitbucket repository URL
]]
])
}
}
}
}
stage('Build') {
steps {
// Replace this with your build commands
sh 'mvn clean install -DskipTests' // Example for a Maven project
}
}
}
post {
success {
echo 'Build successful!'
}
failure {
echo 'Build failed!'
}
}
}
4. Once you have add the script you have to configure JDK, MAVEN, GIT and BITBUCKET CREDENTIALS in the your local machine as well as in Jenkins.
5. To install Them in your machine follow below links.
6. To add them to Jenkins follow below steps.
Got to Dashboard -> Manage Jenkins -> Tools
Go to Dashboard -> Manage Jenkins -> Credentials -> System -> Global credentials (unrestricted) -> Add Credentials
Once you add all the tools modify the pipeline script according to your credentials.
7. Run The build
Go to the Jenkins Job -> Click Build Now
8. You can see the console output of the build