Sobes.tech
Junior — Middle

How did you manage project versions using Jenkins?

sobes.tech AI

Answer from AI

To manage project versions using Jenkins, it is common to integrate a version control system (such as Git) with Jenkins. In Jenkins, a pipeline or job is configured to automatically build and test the project upon each commit to the repository.

Main steps:

  • Connect the Git repository to Jenkins via the Git plugin.
  • Set up a build trigger based on push events or on a schedule.
  • Use variables in the pipeline that reflect the current version (e.g., Git tag or Jenkins build number).
  • Automatically create artifacts with versioned names.

Example Jenkinsfile using version from Git tag:

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        stage('Build') {
            steps {
                script {
                    def version = sh(script: 'git describe --tags', returnStdout: true).trim()
                    echo "Building version ${version}"
                    // build using the version
                }
            }
        }
    }
}