Trigger another CD task, use latest artifacts of another

I have the following structure:

Group A:

  • package
  • library a
  • library b

I would like to rebuild the package (.deb) whenever something changes in library a or b. What i need is something like:

Lib a changes -> recompile lib a -> rebuild package with latest artifacts from library a and library b. Do not rebuild library b if nothing changed.

Is this possible? I know how to setup a basic CD for library a, library b and the package. But I don’t know how to properly connect them.

Thanks!

P.S. its possible to change the folder structure if necessary