woodburn/Jenkinsfile

35 lines
1.4 KiB
Plaintext
Raw Normal View History

2023-07-13 17:19:45 +10:00
pipeline {
agent any
stages {
2023-07-13 18:08:03 +10:00
stage('Test Files') {
2023-07-13 17:19:45 +10:00
steps {
2023-07-13 18:08:03 +10:00
// Search for occurrences of "<filename>.html"
script {
2023-07-13 18:19:54 +10:00
def fileError = false
2023-07-13 18:08:03 +10:00
2023-07-13 18:19:54 +10:00
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()
2023-07-13 18:08:03 +10:00
2023-07-13 18:19:54 +10:00
// If the file contains "<filename>.html", set fileError to true
if (file.contains(filenameWithoutExtension + ".html")) {
fileError = true
}
}
2023-07-13 18:08:03 +10:00
// If affectedFiles is not empty, set fileExists to true
if (affectedFiles) {
fileExists = true
}
// Fail the build and display the affected files
2023-07-13 18:19:54 +10:00
if (fileError) {
2023-07-13 18:08:03 +10:00
error("Error: Found occurrences of 'filename.html' in the following files:\n${affectedFiles}")
}
}
2023-07-13 17:19:45 +10:00
}
}
}
}