From a7a428c7a1d04a4a95f18b720215c4cee48f98a8 Mon Sep 17 00:00:00 2001 From: sisadmin Date: Tue, 14 Jan 2025 16:27:17 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..f890e3b --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,54 @@ +// This Jenkinsfile defines a declarative pipeline +pipeline { +// Specifies that this pipeline can run on any available agent +agent any + +// Defines the sequence of stages that will be executed +stages { +// This stage checks out the source code from the SCM (Source Code Management) system +stage('Checkout') { +steps { +// This command checks out the source code from the SCM into the Jenkins workspace +checkout scm +} +} + +// This stage validates the Packer template +stage('Validate Packer Template') { +steps { +script { +// This command validates the Packer HCL (HashiCorp Configuration Language) template using the provided variable files. Ensure these file names are correct for your setup. +sh "packer validate -var-file variables.pkrvars100GBdisk.hcl -var-file vsphere.pkrvars.hcl ubuntu-22.04.pkr.hcl" +} +} +} + +// This stage builds a VMWare image using Packer +stage('Build VMWare Image') { +when { +// This condition ensures that this stage will only run if the previous 'Validate Packer Template' stage succeeded +expression { currentBuild.resultIsBetterOrEqualTo('SUCCESS') } +} +steps { +script { +// This command builds a VMWare image using Packer with the provided variable files +// It will forcefully build the image even if it exists and will prompt for action on any errors +// Ensure these file names are correct for your setup +sh "packer build -force -on-error=ask -var-file variables.pkrvars100GBdisk.hcl -var-file vsphere.pkrvars.hcl ubuntu-22.04.pkr.hcl" +} +} +} +} + +// Defines actions to be executed after the stages, regardless of their outcome +post { +// This will always archive any .log files in the workspace, even if there are none +always { +archiveArtifacts artifacts: '**/*.log', allowEmptyArchive: true +} +// If any stage failed, this will print an error message +failure { +echo "The build failed. Please check the logs." +} +} +} \ No newline at end of file