Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run(params) {
}
try {
stage('Clone terracumber, susemanager-ci and sumaform') {
// Create a directory for to place the directory with the build results (if it does not exist)
// Create a directory in which to place the build results (if it does not exist)
sh "mkdir -p ${resultdir}"
git url: params.terracumber_gitrepo, branch: params.terracumber_ref
dir("susemanager-ci") {
Expand All @@ -37,9 +37,50 @@ def run(params) {
// Clone sumaform
sh "set +x; source /home/jenkins/.credentials set -x; ./terracumber-cli ${common_params} --gitrepo ${params.sumaform_gitrepo} --gitref ${params.sumaform_ref} --runstep gitsync"

// Restore Terraform states from artifacts
// Attempt to restore Terraform states from artifacts
if (params.use_previous_terraform_state) {
copyArtifacts projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}")
def terraformDir = "${env.WORKSPACE}/sumaform/terraform"
def terraformTmpDir = "${terraformDir}/temp/"
def filters = 'results/sumaform/terraform.tfstate, results/sumaform/.terraform/**/*'
def terraformStatePath = "results/sumaform/terraform.tfstate"
def previousBuild = currentBuild.previousBuild
def found = false

// Loop through previous builds until we find one for which a terraform state was stored
while (previousBuild != null) {
found = fileExists("${WORKSPACE}/${previousBuild.getArtifactsDir()}/${terraformStatePath}")
if (found){
echo "Found previous Terraform state in build ${previousBuild.number}."

// Copy just the necessary files (state and Terraform config) from the previous build to a temporary directory
sh "mkdir -p ${terraformTmpDir}"
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"), filter: "${filters}" , target: "${terraformDir}"
// Copy the Terraform configuration files (like main.tf, variables.tf, etc) from the current workspace to the temp dir
sh "cp ${terraformDir}/*.tf ${terraformTmpDir}"

// Validate the restored Terraform state
dir(terraformTmpDir) {
sh "terraform init"
def planOutput = sh(script: "terraform plan -refresh=true", returnStatus: true)

if (planOutput == 0) {
echo "Terraform state from build ${previousBuild.number} is valid."
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After validating the Terraform state, copyArtifacts is called again on line 68, but artifacts were already copied on line 57. This duplicate copy operation is unnecessary and inefficient. The line 68 copyArtifacts call should be removed since the artifacts have already been copied and validated.

Suggested change
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"

Copilot uses AI. Check for mistakes.
break
} else {
echo "Terraform state from build ${previousBuild.number} is invalid. Searching for another build."
foundState = false
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'foundState' is undefined. This should be 'found' to match the variable declared on line 47. This will cause a runtime error as 'foundState' was never declared.

Suggested change
foundState = false
found = false

Copilot uses AI. Check for mistakes.
}
}
}
previousBuild = previousBuild.previousBuild
}
// Clean up the temp directory
sh "rm -rf ${terraformTmpDir}"

if (!found) {
echo "No previous Terraform state to restore. Starting from scratch."
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,50 @@ def run(params) {
// Clone sumaform
sh "set +x; source /home/jenkins/.credentials set -x; ./terracumber-cli ${common_params} --gitrepo ${params.sumaform_gitrepo} --gitref ${params.sumaform_ref} --runstep gitsync"

// Restore Terraform states from artifacts
// Attempt to restore Terraform states from artifacts
if (params.use_previous_terraform_state) {
copyArtifacts projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}")
def terraformDir = "${env.WORKSPACE}/sumaform/terraform"
def terraformTmpDir = "${terraformDir}/temp/"
def filters = 'results/sumaform/terraform.tfstate, results/sumaform/.terraform/**/*'
def terraformStatePath = "results/sumaform/terraform.tfstate"
def previousBuild = currentBuild.previousBuild
def found = false

// Loop through previous builds until we find one for which a terraform state was stored
while (previousBuild != null) {
found = fileExists("${WORKSPACE}/${previousBuild.getArtifactsDir()}/${terraformStatePath}")
if (found){
echo "Found previous Terraform state in build ${previousBuild.number}."

// Copy just the necessary files (state and Terraform config) from the previous build to a temporary directory
sh "mkdir -p ${terraformTmpDir}"
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"), filter: "${filters}" , target: "${terraformDir}"
// Copy the Terraform configuration files (like main.tf, variables.tf, etc) from the current workspace to the temp dir
sh "cp ${terraformDir}/*.tf ${terraformTmpDir}"

// Validate the restored Terraform state
dir(terraformTmpDir) {
sh "terraform init"
def planOutput = sh(script: "terraform plan -refresh=true", returnStatus: true)

if (planOutput == 0) {
echo "Terraform state from build ${previousBuild.number} is valid."
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After validating the Terraform state, copyArtifacts is called again on line 51, but artifacts were already copied on line 40. This duplicate copy operation is unnecessary and inefficient. The line 51 copyArtifacts call should be removed since the artifacts have already been copied and validated.

Suggested change
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"

Copilot uses AI. Check for mistakes.
break
} else {
echo "Terraform state from build ${previousBuild.number} is invalid. Searching for another build."
foundState = false
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'foundState' is undefined. This should be 'found' to match the variable declared on line 30. This will cause a runtime error as 'foundState' was never declared.

Suggested change
foundState = false
found = false

Copilot uses AI. Check for mistakes.
}
}
}
previousBuild = previousBuild.previousBuild
}
// Clean up the temp directory
sh "rm -rf ${terraformTmpDir}"

if (!found) {
echo "No previous Terraform state to restore. Starting from scratch."
}
}
}
stage('Deploy') {
Expand Down
45 changes: 43 additions & 2 deletions jenkins_pipelines/environments/common/pipeline-reference.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,50 @@ def run(params) {
// Clone sumaform
sh "set +x; source /home/jenkins/.credentials set -x; ./terracumber-cli ${common_params} --gitrepo ${params.sumaform_gitrepo} --gitref ${params.sumaform_ref} --runstep gitsync"

// Restore Terraform states from artifacts
// Attempt to restore Terraform states from artifacts
if (params.use_previous_terraform_state) {
copyArtifacts projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}")
def terraformDir = "${env.WORKSPACE}/sumaform/terraform"
def terraformTmpDir = "${terraformDir}/temp/"
def filters = 'results/sumaform/terraform.tfstate, results/sumaform/.terraform/**/*'
def terraformStatePath = "results/sumaform/terraform.tfstate"
def previousBuild = currentBuild.previousBuild
def found = false

// Loop through previous builds until we find one for which a terraform state was stored
while (previousBuild != null) {
found = fileExists("${WORKSPACE}/${previousBuild.getArtifactsDir()}/${terraformStatePath}")
if (found){
echo "Found previous Terraform state in build ${previousBuild.number}."

// Copy just the necessary files (state and Terraform config) from the previous build to a temporary directory
sh "mkdir -p ${terraformTmpDir}"
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"), filter: "${filters}" , target: "${terraformDir}"
// Copy the Terraform configuration files (like main.tf, variables.tf, etc) from the current workspace to the temp dir
sh "cp ${terraformDir}/*.tf ${terraformTmpDir}"

// Validate the restored Terraform state
dir(terraformTmpDir) {
sh "terraform init"
def planOutput = sh(script: "terraform plan -refresh=true", returnStatus: true)

if (planOutput == 0) {
echo "Terraform state from build ${previousBuild.number} is valid."
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After validating the Terraform state, copyArtifacts is called again on line 51, but artifacts were already copied on line 40. This duplicate copy operation is unnecessary and inefficient. The line 51 copyArtifacts call should be removed since the artifacts have already been copied and validated.

Suggested change
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"

Copilot uses AI. Check for mistakes.
break
} else {
echo "Terraform state from build ${previousBuild.number} is invalid. Searching for another build."
foundState = false
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'foundState' is undefined. This should be 'found' to match the variable declared on line 30. This will cause a runtime error as 'foundState' was never declared.

Suggested change
foundState = false
found = false

Copilot uses AI. Check for mistakes.
}
}
}
previousBuild = previousBuild.previousBuild
}
// Clean up the temp directory
sh "rm -rf ${terraformTmpDir}"

if (!found) {
echo "No previous Terraform state to restore. Starting from scratch."
}
}
}
stage('Deploy') {
Expand Down
46 changes: 44 additions & 2 deletions jenkins_pipelines/environments/common/pipeline-salt-shaker.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,51 @@ def run(params) {
}
// Clone sumaform
sh "set +x; source /home/jenkins/.credentials set -x; ./terracumber-cli ${common_params} --gitrepo ${params.sumaform_gitrepo} --gitref ${params.sumaform_ref} --runstep gitsync"
// Restore Terraform states from artifacts

// Attempt to restore Terraform states from artifacts
if (params.use_previous_terraform_state) {
copyArtifacts projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}")
def terraformDir = "${env.WORKSPACE}/sumaform/terraform"
def terraformTmpDir = "${terraformDir}/temp/"
def filters = 'results/sumaform/terraform.tfstate, results/sumaform/.terraform/**/*'
def terraformStatePath = "results/sumaform/terraform.tfstate"
def previousBuild = currentBuild.previousBuild
def found = false

// Loop through previous builds until we find one for which a terraform state was stored
while (previousBuild != null) {
found = fileExists("${WORKSPACE}/${previousBuild.getArtifactsDir()}/${terraformStatePath}")
if (found){
echo "Found previous Terraform state in build ${previousBuild.number}."

// Copy just the necessary files (state and Terraform config) from the previous build to a temporary directory
sh "mkdir -p ${terraformTmpDir}"
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"), filter: "${filters}" , target: "${terraformDir}"
// Copy the Terraform configuration files (like main.tf, variables.tf, etc) from the current workspace to the temp dir
sh "cp ${terraformDir}/*.tf ${terraformTmpDir}"

// Validate the restored Terraform state
dir(terraformTmpDir) {
sh "terraform init"
def planOutput = sh(script: "terraform plan -refresh=true", returnStatus: true)

if (planOutput == 0) {
echo "Terraform state from build ${previousBuild.number} is valid."
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After validating the Terraform state, copyArtifacts is called again on line 52, but artifacts were already copied on line 41. This duplicate copy operation is unnecessary and inefficient. The line 52 copyArtifacts call should be removed since the artifacts have already been copied and validated.

Suggested change
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"

Copilot uses AI. Check for mistakes.
break
} else {
echo "Terraform state from build ${previousBuild.number} is invalid. Searching for another build."
foundState = false
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'foundState' is undefined. This should be 'found' to match the variable declared on line 31. This will cause a runtime error as 'foundState' was never declared.

Suggested change
foundState = false
found = false

Copilot uses AI. Check for mistakes.
}
}
}
previousBuild = previousBuild.previousBuild
}
// Clean up the temp directory
sh "rm -rf ${terraformTmpDir}"

if (!found) {
echo "No previous Terraform state to restore. Starting from scratch."
}
}
}
stage('Deploy') {
Expand Down
45 changes: 43 additions & 2 deletions jenkins_pipelines/environments/common/pipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,50 @@ def run(params) {
// Clone sumaform
sh "set +x; source /home/jenkins/.credentials set -x; ./terracumber-cli ${common_params} --gitrepo ${params.sumaform_gitrepo} --gitref ${params.sumaform_ref} --runstep gitsync"

// Restore Terraform states from artifacts
// Attempt to restore Terraform states from artifacts
if (params.use_previous_terraform_state) {
copyArtifacts projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}")
def terraformDir = "${env.WORKSPACE}/sumaform/terraform"
def terraformTmpDir = "${terraformDir}/temp/"
def filters = 'results/sumaform/terraform.tfstate, results/sumaform/.terraform/**/*'
def terraformStatePath = "results/sumaform/terraform.tfstate"
def previousBuild = currentBuild.previousBuild
def found = false

// Loop through previous builds until we find one for which a terraform state was stored
while (previousBuild != null) {
found = fileExists("${WORKSPACE}/${previousBuild.getArtifactsDir()}/${terraformStatePath}")
if (found){
echo "Found previous Terraform state in build ${previousBuild.number}."

// Copy just the necessary files (state and Terraform config) from the previous build to a temporary directory
sh "mkdir -p ${terraformTmpDir}"
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"), filter: "${filters}" , target: "${terraformDir}"
// Copy the Terraform configuration files (like main.tf, variables.tf, etc) from the current workspace to the temp dir
sh "cp ${terraformDir}/*.tf ${terraformTmpDir}"

// Validate the restored Terraform state
dir(terraformTmpDir) {
sh "terraform init"
def planOutput = sh(script: "terraform plan -refresh=true", returnStatus: true)

if (planOutput == 0) {
echo "Terraform state from build ${previousBuild.number} is valid."
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After validating the Terraform state, copyArtifacts is called again on line 93, but artifacts were already copied on line 82. This duplicate copy operation is unnecessary and inefficient. The line 93 copyArtifacts call should be removed since the artifacts have already been copied and validated.

Suggested change
copyArtifacts projectName: currentBuild.projectName, selector: specific("${previousBuild.number}"

Copilot uses AI. Check for mistakes.
break
} else {
echo "Terraform state from build ${previousBuild.number} is invalid. Searching for another build."
foundState = false
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'foundState' is undefined. This should be 'found' to match the variable declared on line 72. This will cause a runtime error as 'foundState' was never declared.

Suggested change
foundState = false
found = false

Copilot uses AI. Check for mistakes.
}
}
}
previousBuild = previousBuild.previousBuild
}
// Clean up the temp directory
sh "rm -rf ${terraformTmpDir}"

if (!found) {
echo "No previous Terraform state to restore. Starting from scratch."
}
}

// run minima sync on mirror
Expand Down
Loading