diff --git a/pkg/plugin/deploy/ssh.go b/pkg/plugin/deploy/ssh.go index 51b1da71..59ab7d6d 100644 --- a/pkg/plugin/deploy/ssh.go +++ b/pkg/plugin/deploy/ssh.go @@ -63,11 +63,13 @@ func (s *SSH) Write(f *buildfile.Buildfile) { } } - if len(s.Artifacts) > 1 && !artifact { - artifact = compress(f, s.Artifacts) - } else if len(s.Artifacts) == 1 { - f.WriteCmdSilent(fmt.Sprintf("ARTIFACT=%s", s.Artifacts[0])) - artifact = true + if !artifact { + if len(s.Artifacts) > 1 { + artifact = compress(f, s.Artifacts) + } else if len(s.Artifacts) == 1 { + f.WriteEnv("ARTIFACT", s.Artifacts[0]) + artifact = true + } } if artifact { @@ -82,15 +84,15 @@ func (s *SSH) Write(f *buildfile.Buildfile) { } func createGitArchive(f *buildfile.Buildfile) bool { - f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)") - f.WriteCmdSilent("ARTIFACT=${PWD##*/}-${COMMIT}.tar.gz") + f.WriteEnv("COMMIT", "$(git rev-parse HEAD)") + f.WriteEnv("ARTIFACT", "${PWD##*/}-${COMMIT}.tar.gz") f.WriteCmdSilent("git archive --format=tar.gz --prefix=${PWD##*/}/ ${COMMIT} > ${ARTIFACT}") return true } func compress(f *buildfile.Buildfile, files []string) bool { cmd := "tar -cf ${ARTIFACT} %s" - f.WriteCmdSilent("ARTIFACT=${PWD##*/}.tar.gz") + f.WriteEnv("ARTIFACT", "${PWD##*/}.tar.gz") f.WriteCmdSilent(fmt.Sprintf(cmd, strings.Join(files, " "))) return true } diff --git a/pkg/plugin/deploy/ssh_test.go b/pkg/plugin/deploy/ssh_test.go index e3f4fc18..53e25a29 100644 --- a/pkg/plugin/deploy/ssh_test.go +++ b/pkg/plugin/deploy/ssh_test.go @@ -119,6 +119,10 @@ func TestSSHGitArchive(t *testing.T) { t.Errorf("Expect script to contains artifact") } + if strings.Contains(bscr, "=GITARCHIVE") { + t.Errorf("Doesn't expect script to contains GITARCHIVE literals") + } + if !strings.Contains(bscr, "git archive --format=tar.gz --prefix=${PWD##*/}/ ${COMMIT} > ${ARTIFACT}") { t.Errorf("Expect script to run git archive") }