2021年7月29日 星期四

Implicitly loading submodules in Jenkins pipeline stages

I assume you have been using the git step so far to clone a repository.

However for advanced features (like submodules) there's the checkout step available: https://jenkins.io/doc/pipeline/steps/workflow-scm-step/

The checkout steps provides an option to update all submodules and can even update the submodules recursively, e.g.:

checkout([$class: 'GitSCM',
    branches: [[name: '*/master']],
    doGenerateSubmoduleConfigurations: false,
    extensions: [[$class: 'SubmoduleOption',
        disableSubmodules: false,
        parentCredentials: false,
        recursiveSubmodules: false,
        reference: '',
        trackingSubmodules: false
    ]],
    submoduleCfg: [],
    userRemoteConfigs: [[url: 'ssh://myserver/myrepo']]
])

What actually enables cloning of the submodules is the SubmoduleOption extension as seen in the example above.

As the syntax is - let's say - little bit more complex I recommend using the snipped generator. 


from: https://stackoverflow.com/questions/51361907/implicitly-loading-submodules-in-jenkins-pipeline-stages

2021年7月28日 星期三

Get the current commit id of specified submodule

 You can start with git ls-files -s (as in this answer)

cd /path/to/parent/repo
git ls-files -s yourSubmodule


from: https://stackoverflow.com/questions/32327108/get-the-current-commit-id-of-specified-submodule

How to get the last commit ID of a remote repo using curl-like command?

 git log --format="%H" -n 1


from: https://stackoverflow.com/questions/19176359/how-to-get-the-last-commit-id-of-a-remote-repo-using-curl-like-command

2021年7月27日 星期二

using “git submodule foreach” can you skip a list of submodules?

 lets say I have 10 submoules:

module/1
module/2
module/3
module/4
module/5
module/6
module/7
module/8
module/9
module/10

so use the shell:

 git submodule foreach 'case $name in 4|6|7) git status ;; *) git status ;; esac'

from: https://stackoverflow.com/questions/58291315/using-git-submodule-foreach-can-you-skip-a-list-of-submodules

Check if git submodule has been updated on remote

 Based on https://stackoverflow.com/a/3278427/7976758 I'd do something like this:

git submodule foreach git remote update
git submodule foreach git --no-pager diff origin/master master

If submodules use different branches the script needs to take that into account.


from: https://stackoverflow.com/questions/50965094/check-if-git-submodule-has-been-updated-on-remote