Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
solve the concrete problem for git branch name that starts with #
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-ts committed Jun 12, 2017
1 parent 1223059 commit 3a0f7c6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
// the "!#/usr/bin... is just to to help IDEs, GitHub diffs, etc properly detect the language and do syntax highlighting for you.
// thx to https://github.com/jenkinsci/pipeline-examples/blob/master/docs/BEST_PRACTICES.md

/**
* According to the documentation at https://docs.docker.com/engine/reference/commandline/tag/ :
* A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters.
*/
def String mkDockerTag(String input)
{
return input
.replaceFirst('^[#\\.]', '') // delete the first letter if it is a period or dash
.replaceAll('[^a-zA-Z0-9_#\\.]', '_'); // replace everything that's not allowed with an underscore
}

def boolean isRepoExists(String repoId)
{
Expand Down Expand Up @@ -256,8 +266,8 @@ node('agent && linux && dejenkinsnode001') // shall only run on a jenkins agent
docker.withRegistry('https://index.docker.io/v1/', 'dockerhub_metasfresh')
{
def app = docker.build 'metasfresh/metasfresh-admin', 'src/main/docker';
app.push "${MF_UPSTREAM_BRANCH}-latest";
app.push "${MF_UPSTREAM_BRANCH}-${BUILD_VERSION}";
app.push mkDockerTag("${MF_UPSTREAM_BRANCH}-latest");
app.push mkDockerTag("${MF_UPSTREAM_BRANCH}-${BUILD_VERSION}");
}
}
}
Expand Down

0 comments on commit 3a0f7c6

Please sign in to comment.