Hi guys,
I am working on my drone CI pipeline facing following issue:
My git repo looks like this:
myrepo -> .drone.yml -> images/ -> a1/ -> a1script -> Dockerfile -> a2/ -> a2script -> Dockerfile -> a3/ -> a3script -> Dockerfile -> a-final/ -> Dockerfile
a-final depends on a3 to build and publish it’s image on our artifactory and same for others - a3 depends on a2 and a2 depends on a1.
Now, in my .drone.yml what I want is if a module has been changed in git repo - then only that module and all it’s dependent modules should be build and published (there is only 1 “step” for each module in my .drone.yml file to publish) one after another and not all of them. For example, If I push some code in a2, then only a2, a3 and a-final should be built and published in order a2, a3, a-final.
I tried doing that in my .drone.yml but can’t control the behavior even with using conditions like status:success OR environment variables.
This is how the first 2 modules (a1 and a2) of my .drone.yml looks like:
pipeline:
# Get the latest git diff and see what directories changed. check_clone: image: plugins/git commands: - git diff-tree --no-commit-id --name-only -r `git log | head -1 | awk '{print $2}'` > git_latest_delta - cat ./git_latest_delta - echo "Done!" # Check if a1 is in the diff list - if not then exit 1 a1_build: image: ubuntu:bionic commands: - ./is_build_required a1 # Publish a1 on some condition - like if previous step is successful or if an env variable is set. a1_publish: image: plugins/docker:17.05 registry: docker.mycompany.com repo: docker.mycompany.com/app/a1 dockerfile: images/a1/Dockerfile tags: - "${DRONE_COMMIT:0:8}" when: status: success username: myuser secrets: - source: artifactory_password target: plugin_password a2_build: image: ubuntu:bionic commands: - echo $$DRONE_TAG - ./is_build_required a2 when: status: [ success, failure ] # Don't know how to get at this step as if a1 publish is skipped then pipeline fails and the below step doesn't execute. :( a2_publish: image: plugins/docker:17.05 registry: docker.mycompany.com repo: docker.mycompany.com/app/a2 dockerfile: images/a2/Dockerfile tags: - "${DRONE_COMMIT:0:8}" when: status: success username: svcpejkn001 secrets: - source: artifactory_password target: plugin_password
Same for a3 and a-final. This how I need to control the pipeline build process.
I tried with custom environment variables but couldn’t control the “when:” field in step because it doesn’t accept our defined variables - it only goes with fixed things like status, branch, repo, etc.
So, please help me.
Thanks,
Neo