From 96a5de48a52012fb6431794d4b34602c743fe264 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 13 Jul 2023 18:36:36 +1000 Subject: [PATCH] cd: html test 3 --- Jenkinsfile | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 27fb214..a763b1a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,31 +2,26 @@ pipeline { agent any stages { - stage('Test Files') { + stage('Check HTML Files') { steps { - // Search for occurrences of ".html" + // Search for occurrences of "filename.html" script { - def fileError = false + def fileExists = false - def allFiles = sh returnStdout: true, script: 'find . -type f -name "*.html" -print0 | xargs -0 grep -l ".html"' - - // For each file, check if it contains ".html" - allFiles.eachLine { file -> - def filename = file.split("/").last() - def filenameWithoutExtension = filename.split("\\.").first() + // Find files with "filename.html" occurrences + def affectedFiles = sh( + script: 'find . -type f -name "*.html" -print0 | xargs -0 grep -l ".html"', + returnStdout: true + ).trim() - // If the file contains ".html", set fileError to true - if (file.contains(filenameWithoutExtension + ".html")) { - fileError = true - } - } // If affectedFiles is not empty, set fileExists to true if (affectedFiles) { fileExists = true } + // Fail the build and display the affected files - if (fileError) { - error("Error: Found occurrences of 'filename.html' in the following files:\n${affectedFiles}") + if (fileExists) { + error("Error: Found occurrences of '.html' in the following files:\n${affectedFiles}") } } }