diff --git a/buildtrigger/basehandler.py b/buildtrigger/basehandler.py index a991c3be9..64647e06c 100644 --- a/buildtrigger/basehandler.py +++ b/buildtrigger/basehandler.py @@ -290,7 +290,10 @@ class BuildTriggerHandler(object): def get_dockerfile_path(self): """ Returns the normalized path to the Dockerfile found in the subdirectory in the config. """ - return self.config.get('subdir', '') + dockerfile_path = self.config.get('subdir') or 'Dockerfile' + if dockerfile_path[0] == '/': + dockerfile_path = dockerfile_path[1:] + return dockerfile_path def prepare_build(self, metadata, is_manual=False): # Ensure that the metadata meets the scheme. diff --git a/buildtrigger/githubhandler.py b/buildtrigger/githubhandler.py index 80dd5e2aa..f6687798e 100644 --- a/buildtrigger/githubhandler.py +++ b/buildtrigger/githubhandler.py @@ -371,6 +371,9 @@ class GithubBuildTrigger(BuildTriggerHandler): raise RepositoryReadException(message) path = self.get_dockerfile_path() + if not path: + return None + try: file_info = repo.get_file_contents(path) except GithubException as ghe: diff --git a/buildtrigger/test/bitbucketmock.py b/buildtrigger/test/bitbucketmock.py index 93d66d143..c53f4a57f 100644 --- a/buildtrigger/test/bitbucketmock.py +++ b/buildtrigger/test/bitbucketmock.py @@ -23,7 +23,7 @@ def get_repo_path_contents(path, revision): return (True, data, None) def get_raw_path_contents(path, revision): - if path == '/Dockerfile': + if path == 'Dockerfile': return (True, 'hello world', None) if path == 'somesubdir/Dockerfile': diff --git a/buildtrigger/test/githubmock.py b/buildtrigger/test/githubmock.py index 77c8a7a1f..f42ec57ca 100644 --- a/buildtrigger/test/githubmock.py +++ b/buildtrigger/test/githubmock.py @@ -119,7 +119,7 @@ def get_mock_github(): return [master, otherbranch] def get_file_contents_mock(filepath): - if filepath == '/Dockerfile': + if filepath == 'Dockerfile': m = Mock() m.content = 'hello world' return m diff --git a/buildtrigger/test/gitlabmock.py b/buildtrigger/test/gitlabmock.py index 8a2212be9..c7d4a5865 100644 --- a/buildtrigger/test/gitlabmock.py +++ b/buildtrigger/test/gitlabmock.py @@ -151,7 +151,7 @@ def gettag_mock(repo_id, tag): } def getrawfile_mock(repo_id, branch_name, path): - if path == '/Dockerfile': + if path == 'Dockerfile': return 'hello world' if path == 'somesubdir/Dockerfile':