diff options
| -rw-r--r-- | Jenkinsfile | 6 | ||||
| -rwxr-xr-x | clean.sh | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/Jenkinsfile b/Jenkinsfile index ac13c16..8c386c2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,12 +8,14 @@ node("master") { checkout scm dir("/home/oleg/majordomo") { - List<String> gitDirectories = (sh (script: "ls --directory -1 */*", returnStdout: true)).split("\n") + List<String> gitDirectories = (sh (script: 'ls --directory -1 */*', returnStdout: true)).split("\n") gitDirectories.collate(params.PARALLEL.toInteger()) .each { directories -> parallel (directories.collectEntries { directory -> [(directory): {warnError("Failed to update Git repository in $directory"){ - sh "git -C $directory checkout master || git -C $directory pull --rebase; git -C $directory pull --rebase" + sh (["git -C $directory checkout master || true", + "git -C $directory pull --rebase", + "$WORKSPACE/clean.sh $directory"].join("; ")) }}] }) } diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..c317bc6 --- /dev/null +++ b/clean.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -ex + +PAGER=cat +EMAIL="go.wigust@gmail.com" + +repository="$1" +for branch in $(git -C $repository branch --remotes | grep -v 'HEAD\|master'); do + [[ $(git -C $repository log --format='%ae' $branch | head -1) == "$EMAIL" ]] \ + && git -C $repository push --delete origin ${branch#origin/} \ + || echo "$branch doesn't belong to $EMAIL or doesn't exists on remote." +done |
