cd: Error if html in file test 2
Some checks failed
nathanwoodburn/woodburn/pipeline/head There was a failure building this commit

This commit is contained in:
Nathan Woodburn 2023-07-13 18:19:54 +10:00
parent 8331ede34c
commit 5875acefa2
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

20
Jenkinsfile vendored
View File

@ -6,20 +6,26 @@ pipeline {
steps {
// Search for occurrences of "<filename>.html"
script {
def fileExists = false
def fileError = false
// Find files with "<filename>.html" occurrences
def affectedFiles = sh returnStdout: true, script: 'grep -rl ".html" ./*.html'
// Trim
affectedFiles = affectedFiles.trim()
def allFiles = sh returnStdout: true, script: 'find . -type f -name "*.html" -print0 | xargs -0 grep -l ".html"'
// For each file, check if it contains "<filename>.html"
allFiles.eachLine { file ->
def filename = file.split("/").last()
def filenameWithoutExtension = filename.split("\\.").first()
// If the file contains "<filename>.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 (fileExists) {
if (fileError) {
error("Error: Found occurrences of 'filename.html' in the following files:\n${affectedFiles}")
}
}