How to divide reusable tasks yet using a single Docker container?

Fabien Lydoire April 24, 2023

Hello there !

I am new to Bitbucket pipelines coming from Jenkins.
I want to have a pipeline with the following tasks:

  1. Setup Javascript dependencies
  2. Lint code
  3. Generate doc
  4. Execute tests
  5. Report tests results to PR

I implemented those tasks using multiple step .
All steps are using the same Docker container which is cached and restored for each step. This process of caching/restoring is time consuming.
Also, those steps are defined and then used as YAML anchors and references to avoid duplication: reshuffled steps depending on the branch (a feature branch, develop, main, …).

My question: Is there a way to get all the following:

  • Simple tasks reusable (just like step and YAML reference)
  • All tasks using the same Docker container without cache/restore
  • Visual representation in the Pipeline layout of the individual tasks to quickly identify where the issue, if any, was raised.

Thanks for your support !

 

1 answer

0 votes
Erez Maadani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2023

Hi @Fabien Lydoire 

If your commands are one-line, just have one step per branch type/group and run them together.

If the commands are more complex, my recommendation is to implement these tasks externally to the pipeline/steps, IE, use a build script: gradle, maven, sh file, etc'. This will simplify the commands, or even group of commands, to one-liners and you can use the first option. 

Fabien Lydoire April 24, 2023

one step per branch (...) and run them together

Yes I can do that, but it does not match my third requirement:

  • Visual representation in the Pipeline layout of the individual tasks to quickly identify where the issue, if any, was raised.

Having a single step means having a single node in the Pipeline graph. I wish I could split tasks within a single node.

Erez Maadani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2023

Here is the visual representation you would have:

Screenshot 2023-04-25 at 10.14.41.png

You can see each command has its own line so it's very easy to see which one failed.

Basically, each step in the pipeline is running on a different container. if you need to share data between the steps, you would need to use cache/artifacts mechanism or some other way to inject the data into the containers (git clone/ftp/download/etc'). 

Fabien Lydoire May 30, 2023

Thanks @Erez Maadani I understand that there are no better options.

I implemented my Bitbucket pipeline according to your suggestion.

I saves run time, yet I'm still frustrated with the single step green bullet in the pipeline graphical view.... 🤷🏻‍♂️

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events