fix(pipeline): refine buildArtifacts handling to support directory and file stashing
Signed-off-by: 孙振宇 <>
This commit is contained in:
parent
b0a0285029
commit
818e4670b8
4
first-class-pipeline/tests/Jenkinsfile
vendored
4
first-class-pipeline/tests/Jenkinsfile
vendored
@ -42,7 +42,7 @@ executeFreeleapsPipeline {
|
|||||||
// buildCommand used to specify the build command of the component
|
// buildCommand used to specify the build command of the component
|
||||||
buildCommand: 'npm run build',
|
buildCommand: 'npm run build',
|
||||||
// buildArtifacts used to specify the build artifacts that needs to be stores and shares between components
|
// buildArtifacts used to specify the build artifacts that needs to be stores and shares between components
|
||||||
buildArtifacts: ['dist/**'],
|
buildArtifacts: ['dist'],
|
||||||
// lintEnabled used to specify whether to enable code lint
|
// lintEnabled used to specify whether to enable code lint
|
||||||
lintEnabled: false,
|
lintEnabled: false,
|
||||||
// linter used to specify the code linter
|
// linter used to specify the code linter
|
||||||
@ -91,7 +91,7 @@ executeFreeleapsPipeline {
|
|||||||
// buildAgentImage used to specify the build environment container image
|
// buildAgentImage used to specify the build environment container image
|
||||||
buildAgentImage: 'python:3.8-slim-buster',
|
buildAgentImage: 'python:3.8-slim-buster',
|
||||||
// buildArtifacts used to specify the build artifacts that needs to be stores and shares between components
|
// buildArtifacts used to specify the build artifacts that needs to be stores and shares between components
|
||||||
buildArtifacts: ['./**'],
|
buildArtifacts: ['.'],
|
||||||
// buildCacheEnabled used to specify whether to enable build dependencies cache
|
// buildCacheEnabled used to specify whether to enable build dependencies cache
|
||||||
buildCacheEnabled: true,
|
buildCacheEnabled: true,
|
||||||
// buildCommand used to specify the build command of the component
|
// buildCommand used to specify the build command of the component
|
||||||
|
|||||||
@ -319,6 +319,24 @@ def generateComponentStages(component, configurations) {
|
|||||||
sh component.buildCommand
|
sh component.buildCommand
|
||||||
}
|
}
|
||||||
component.buildArtifacts.each { artifact ->
|
component.buildArtifacts.each { artifact ->
|
||||||
|
steps.log.info("Pipeline", "Stashing artifact ${artifact} for ${component.name}...")
|
||||||
|
def targetPathType = sh(
|
||||||
|
script: """
|
||||||
|
if [ -d "${artifact}" ]; then
|
||||||
|
echo "dir"
|
||||||
|
elif [ -f "${artifact}" ]; then
|
||||||
|
echo "file"
|
||||||
|
else
|
||||||
|
echo "unknown"
|
||||||
|
fi
|
||||||
|
""",
|
||||||
|
returnStdout: true
|
||||||
|
)
|
||||||
|
if (artifact == '.' || artifact == './') {
|
||||||
|
stash includes: ".", name: "${component.name}-root"
|
||||||
|
} else if (targetPathType.trim() == "dir") {
|
||||||
|
stash includes: "${artifact}/**", name: "${component.name}-${artifact}"
|
||||||
|
} else {
|
||||||
stash includes: artifact, name: "${component.name}-${artifact}"
|
stash includes: artifact, name: "${component.name}-${artifact}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,6 +345,7 @@ def generateComponentStages(component, configurations) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// Image Builder Setup
|
// Image Builder Setup
|
||||||
stage("${component.name} :: Image Builder Setup") {
|
stage("${component.name} :: Image Builder Setup") {
|
||||||
@ -377,8 +396,12 @@ def generateComponentStages(component, configurations) {
|
|||||||
|
|
||||||
dir(env.workroot + "/" + component.root) {
|
dir(env.workroot + "/" + component.root) {
|
||||||
component.buildArtifacts.each { artifact ->
|
component.buildArtifacts.each { artifact ->
|
||||||
|
if (artifact == '.' || artifact == './') {
|
||||||
|
unstash "${component.name}-root"
|
||||||
|
} else {
|
||||||
unstash "${component.name}-${artifact}"
|
unstash "${component.name}-${artifact}"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (component.dockerfile != null && !component.dockerfile.isEmpty()) {
|
if (component.dockerfile != null && !component.dockerfile.isEmpty()) {
|
||||||
log.error("Pipeline", "Component ${component.name} dockerfile not set!")
|
log.error("Pipeline", "Component ${component.name} dockerfile not set!")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user