Skip to content

Commit 1b34cd9

Browse files
committed
jenkins_build.sh: refactor the code for balena.img handling
No functional change, just refactor a section of the script to make it more readable. Change-type: patch Signed-off-by: Michal Toman <michalt@balena.io>
1 parent 9b5f5d2 commit 1b34cd9

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

automation/jenkins_build.sh

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,9 @@ deploy_build () {
8484
cp -v "$YOCTO_BUILD_DEPLOY/kernel_modules_headers.tar.gz" "$_deploy_dir" || true
8585
cp -v "$YOCTO_BUILD_DEPLOY/kernel_source.tar.gz" "$_deploy_dir" || true
8686
cp -v "$MACHINE.svg" "$_deploy_dir/logo.svg"
87-
if [ "${_compressed}" != 'true' ]; then
88-
# uncompressed, just copy and we're done
89-
cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_artifact") "$_deploy_dir/image/balena.img"
90-
if [ -n "$_deploy_flasher_artifact" ]; then
91-
cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-raw.img"
92-
cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_flasher_artifact") "$_deploy_dir/image/balena-flasher.img"
93-
elif [ "$_image" = "resin-image-flasher" ]; then
94-
# backwards compatibility - deployFlasherArtifact is not set and deployArtifact contains flasher
95-
cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-flasher.img"
96-
else
97-
cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-raw.img"
98-
fi
99-
return
100-
fi
10187

102-
if [ "${_archive}" = 'true' ]; then
88+
if [ "${_archive}" = 'true' ] && [ "${_compressed}" = 'true' ]; then
89+
# Archive and we are done
10390
cp -rv "$YOCTO_BUILD_DEPLOY"/"$_deploy_artifact"/* "$_deploy_dir"/image/
10491
(cd "$_deploy_dir/image/" && zip -r "../$_deploy_artifact.zip" .)
10592
if [ -n "$_deploy_flasher_artifact" ]; then
@@ -109,28 +96,40 @@ deploy_build () {
10996
if [ "$_remove_compressed_file" = "true" ]; then
11097
rm -rf $_deploy_dir/image
11198
fi
99+
return
100+
fi
101+
102+
cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_artifact") "$_deploy_dir/image/balena-raw.img"
103+
if [ -n "$_deploy_flasher_artifact" ]; then
104+
cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_flasher_artifact") "$_deploy_dir/image/balena-flasher.img"
105+
elif [ "$_image" = "resin-image-flasher" ]; then
106+
# deployFlasherArtifact is not set and deployArtifact contains flasher
107+
mv "$_deploy_dir/image/balena-raw.img" "$_deploy_dir/image/balena-flasher.img"
108+
fi
109+
110+
# Create the unflagged balena.img for backwards compatibility
111+
if [ "$_image" = "resin-image-flasher" ]; then
112+
cp -v "$_deploy_dir/image/balena-flasher.img" "$_deploy_dir/image/balena.img"
112113
else
113-
cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_artifact") "$_deploy_dir/image/balena.img"
114-
(cd "$_deploy_dir/image" && zip balena.img.zip balena.img)
115-
if [ -n "$_deploy_flasher_artifact" ]; then
116-
cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-raw.img"
117-
(cd "$_deploy_dir/image" && zip balena-raw.img.zip balena-raw.img)
118-
cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_flasher_artifact") "$_deploy_dir/image/balena-flasher.img"
119-
(cd "$_deploy_dir/image" && zip balena-flasher.img.zip balena-flasher.img)
120-
elif [ "$_image" = "resin-image-flasher" ]; then
121-
# backwards compatibility - deployFlasherArtifact is not set and deployArtifact contains flasher
122-
cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-flasher.img"
123-
(cd "$_deploy_dir/image" && zip balena-flasher.img.zip balena-flasher.img)
124-
else
125-
cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-raw.img"
126-
(cd "$_deploy_dir/image" && zip balena-raw.img.zip balena-raw.img)
114+
cp -v "$_deploy_dir/image/balena-raw.img" "$_deploy_dir/image/balena.img"
115+
fi
116+
117+
if [ "${_compressed}" != 'true' ]; then
118+
# uncompressed, just copy and we're done
119+
return
120+
fi
121+
122+
for filename in balena.img balena-raw.img balena-flasher.img; do
123+
if [ ! -f "$_deploy_dir/image/$filename" ]; then
124+
continue
127125
fi
126+
127+
(cd "$_deploy_dir/image" && zip "$filename.zip" "$filename")
128+
128129
if [ "$_remove_compressed_file" = "true" ]; then
129-
rm -rf $_deploy_dir/image/balena.img
130-
rm -rf $_deploy_dir/image/balena-raw.img
131-
rm -rf $_deploy_dir/image/balena-flasher.img
130+
rm -rf "$_deploy_dir/image/$filename"
132131
fi
133-
fi
132+
done
134133

135134
if [ -d "${WORKSPACE}/layers/meta-balena/tests" ]
136135
then

0 commit comments

Comments
 (0)