What im trying to do is a simple build → test → analyze
Looking at all the examples it seems that these should be defined as “jobs”.
I did that method and get everything working
snippet:
build_local:
type: build
tags:
- linux
script: "cd build && cmake .. && make -j12"
test_local:
type: test
tags:
- linux
script: "cd build && cmake .. && make -j12 && ctest -j12"
analyze_local:
type: analyze
tags:
- linux
- sonar
only:
- master
script: "cd build && cmake .. && make -j12 && ctest -j12 && make sonar"
however doing this means that every step has to build and run tests.
I was thinking of just disabling all the jobs except for “analyze_local” as it does the other two steps as well.
Is there a more elegant way of doing this? or is there anyway to share the build artifacts to the next phase for the same job?
ex. Build → spit out a binary, then pass those to the “test” job so i dont have to rebuild the same files again.
What you are looking for here are the parameters artifacts and dependencies. artifacts parameter informs about the files and folders that must be kept after the job is done and dependencies informs about what job should be done (and succeeded) before starting the current one.
In your case, I think what you are looking at is:
build_local:
type: build
tags:
- linux
script: "cd build && cmake .. && make -j12"
artifacts:
paths:
- build/
test_local:
type: test
tags:
- linux
script: "cd build && ctest -j12"
dependencies:
- build_local
artifacts:
paths:
- build/
analyze_local:
type: analyze
tags:
- linux
- sonar
only:
- master
script: "cd build && make sonar"
dependencies:
- test_local
Maybe you should specify the files you want to keep instead of all the build directory because you may not need all the generated files.
Hope that helped you or will help someone in the future!