英文:
Why bitbucket ends up in GREEN though recent command exits with a non-zero code?
问题
I've a simple Dockerfile that just pushes the newly built .apk file to the Google Play Console with help of Fastlane tool.
Dockerfile
FROM ruby:3.0-slim-buster
WORKDIR /app
# Copy android project contents. It has an .apk file at ./android/app/build/outputs/apk/release/app-release.apk
COPY ./android .
RUN rm Gemfile.lock
# Install Fastlane
RUN apt-get update
RUN apt-get install build-essential -y
RUN gem install bundler
RUN bundle install
# Upload the apk file
ENTRYPOINT bundle exec fastlane upload
docker-compose.yml
version: '3'
services:
push-android:
build:
dockerfile: ./android/Dockerfile
context: .
deploy:
resources:
reservations:
memory: 2048M
networks:
- internal
networks:
internal:
driver: bridge
My bitbucket-pipelines.yml
step goes like this:
- step:
name: Push APK File
caches:
- docker
- node
services:
- docker
size: 2x
script:
- docker-compose up push-android
When I run the above step, it pushes .apk file successfully to the Google Play console. All good with the code so far and with Bitbucket pipeline as well.
But if I re-run the pipeline, it is expected to fail (the Bitbucket pipeline should end up in RED, because we already uploaded an .apk with the same versionCode already in the previous build pipeline). As expected, command bundle exec fastlane upload
fails with non-zero exit code. But the pipeline still ends up in GREEN. But I expect to see it in RED.
Sharing captured image to see the problem visually.
I've even tried by simplifying the Dockerfile to debug the issue by reducing the blast radius or suspicious area.
Updated Dockerfile
FROM ruby:3.0-slim-buster
# There is NO such shell script with this name. So, it should fail with some non-zero exit code.
ENTRYPOINT ./push-apk.sh
Sharing captured image to see the problem visually.
May also this information is useful to you to understand the situation better. If any command while building the image fails, I see the Bitbucket pipeline ends up in RED as expected. Ex, Dockerfile
FROM ruby:3.0-slim-buster
# There is NO such shell script with this name. So, it should fail with some non-zero exit code.
RUN ./push-apk.sh
Bitbucket pipeline ends up in RED when I run the above Dockerfile
changes.
Explained above, all the different situations that I encountered/tried to debug the issue. Hope it's all helpful. According to Bitbucket docs, the build will fail (or go RED) if the exit code is non-zero. As part of the debugging process, I've even tried after-script from Bitbucket to log the $BITBUCKET_EXIT_CODE
. It logged 0
exit code, that's why we see GREEN. But I don't know how to debug further, that why my shell command exit code is not passed to the pipeline? or why $BITBUCKET_EXIT_CODE
is 0
.
Could someone tell me where I'm going wrong by considering the above situations? Why my Bitbucket pipeline doesn't go RED when the recent executed command fails with a non-zero exit code?
英文:
I've a simple Dockerfile that just pushes the newly built .apk file to the Google Play Console with help of Fastlane tool.
Dockerfile
FROM ruby:3.0-slim-buster
WORKDIR /app
# Copy android project contents. It has an .apk file at ./android/app/build/outputs/apk/release/app-release.apk
COPY ./android .
RUN rm Gemfile.lock
# Install Fastlane
RUN apt-get update
RUN apt-get install build-essential -y
RUN gem install bundler
RUN bundle install
# Upload the apk file
ENTRYPOINT bundle exec fastlane upload
docker-compose.yml
version: '3'
services:
push-android:
build:
dockerfile: ./android/Dockerfile
context: .
deploy:
resources:
reservations:
memory: 2048M
networks:
- internal
networks:
internal:
driver: bridge
My bitbucket-pipelines.yml
step goes like this:
- step:
name: Push APK File
caches:
- docker
- node
services:
- docker
size: 2x
script:
- docker-compose up push-android
When I run the above step, it pushes .apk file successfully to the Google Play console. All good with the code so far and with Bitbucket pipeline as well.
But if I re-run the pipeline, it is expected to fail(the Bitbucket pipeline should end up in RED, because we already uploaded an .apk with the same versionCode already in previous build pipeline). As expected, command bundle exec fastlane upload
fails with non-zero exit code. But pipeline still ends up in GREEN. But I expect to see it in RED.
Sharing captured image to see the problem visually.
I've even tried by simplifying the Dockerfile to debug the issue by reducing the blast radius or suspicious area.
Updated Dockerfile
FROM ruby:3.0-slim-buster
# There is NO such shell script with this name. So, it should fail with some non-zero exit code.
ENTRYPOINT ./push-apk.sh
Sharing captured image to see the problem visually.
May also this information is useful to you to understand the situation better.
If any command while building the image fails, I see bitbucket pipeline ends up in RED as expected.
Ex, Dockerfile
FROM ruby:3.0-slim-buster
# There is NO such shell script with this name. So, it should fail with some non-zero exit code.
RUN ./push-apk.sh
Bitbucket pipeline ends up in RED when I run above Dockerfile
changes.
Explained above, all the different situations that I encountered/tried to debug the issue. Hope it's all helpful.
According to bitbucket docs, build will fail(or go RED) if exit code is non-zero.
As part of debugging process, I've even tried after-script from Bitbucket to log the $BITBUCKET_EXIT_CODE
. It logged 0
exit code, that's why we see GREEN. But I don't know how to debug further, that why my shell command exit code is not passed to pipeline? or why $BITBUCKET_EXIT_CODE
is 0
.
Could someone tell me where I'm going wrong by considering the above situations? Why my bitbucket pipeline doesn't go RED when the recent executed command fail with a non-zero exit code?
答案1
得分: 2
因为 docker-compose up push-android
本身不会在服务以非零代码退出时失败。
在这种情况下,您可能想要使用 docker-compose run push-android
。这将传播退出代码。
英文:
Because docker-compose up push-android
itself does not fail if a service exits with a non-zero code.
You probably want docker-compose run push-android
instead in this context. This will propagate the exit code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论