Commit e4cc3342 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Pass `expire_in` from `artifacts:expire_in` when uploading artifacts to POST request

parent 1a5a7a31
......@@ -38,7 +38,7 @@ func (m *testNetwork) DownloadArtifacts(config common.BuildCredentials, artifact
return m.downloadState
}
func (m *testNetwork) UploadRawArtifacts(config common.BuildCredentials, reader io.Reader, baseName string) common.UploadState {
func (m *testNetwork) UploadRawArtifacts(config common.BuildCredentials, reader io.Reader, baseName string, expireIn string) common.UploadState {
m.uploadCalled++
if m.uploadState == common.UploadSucceeded {
......
......@@ -22,7 +22,8 @@ type ArtifactsUploaderCommand struct {
retryHelper
network common.Network
Name string `long:"name" description:"The name of the archive"`
Name string `long:"name" description:"The name of the archive"`
ExpireIn string `long:"expire-in" description:"When to expire artifacts"`
}
func (c *ArtifactsUploaderCommand) createAndUpload() (bool, error) {
......@@ -38,7 +39,7 @@ func (c *ArtifactsUploaderCommand) createAndUpload() (bool, error) {
artifactsName := path.Base(c.Name) + ".zip"
// Upload the data
switch c.network.UploadRawArtifacts(c.BuildCredentials, pr, artifactsName) {
switch c.network.UploadRawArtifacts(c.BuildCredentials, pr, artifactsName, c.ExpireIn) {
case common.UploadSucceeded:
return false, nil
case common.UploadForbidden:
......
......@@ -135,7 +135,7 @@ type Network interface {
VerifyRunner(config RunnerCredentials) bool
UpdateBuild(config RunnerConfig, id int, state BuildState, trace string) UpdateState
DownloadArtifacts(config BuildCredentials, artifactsFile string) DownloadState
UploadRawArtifacts(config BuildCredentials, reader io.Reader, baseName string) UploadState
UploadRawArtifacts(config BuildCredentials, reader io.Reader, baseName string, expireIn string) UploadState
UploadArtifacts(config BuildCredentials, artifactsFile string) UploadState
ProcessBuild(config RunnerConfig, id int) BuildTrace
}
......@@ -58,8 +58,8 @@ func (m *Network) DownloadArtifacts(config common.BuildCredentials, artifactsFil
return r0
}
func (m *Network) UploadRawArtifacts(config common.BuildCredentials, reader io.Reader, baseName string) common.UploadState {
ret := m.Called(config, reader, baseName)
func (m *Network) UploadRawArtifacts(config common.BuildCredentials, reader io.Reader, baseName string, expireIn string) common.UploadState {
ret := m.Called(config, reader, baseName, expireIn)
r0 := ret.Get(0).(common.UploadState)
......
......@@ -9,6 +9,7 @@ import (
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
"os"
"path/filepath"
"runtime"
......@@ -221,7 +222,7 @@ func (n *GitLabClient) createArtifactsForm(mpw *multipart.Writer, reader io.Read
return nil
}
func (n *GitLabClient) UploadRawArtifacts(config common.BuildCredentials, reader io.Reader, baseName string) common.UploadState {
func (n *GitLabClient) UploadRawArtifacts(config common.BuildCredentials, reader io.Reader, baseName string, expireIn string) common.UploadState {
pr, pw := io.Pipe()
defer pr.Close()
......@@ -243,9 +244,14 @@ func (n *GitLabClient) UploadRawArtifacts(config common.BuildCredentials, reader
TLSCAFile: config.TLSCAFile,
}
query := url.Values{}
if expireIn != "" {
query.Set("expire_in", expireIn)
}
headers := make(http.Header)
headers.Set("BUILD-TOKEN", config.Token)
res, err := n.doRaw(mappedConfig, "POST", fmt.Sprintf("builds/%d/artifacts", config.ID), pr, mpw.FormDataContentType(), headers)
res, err := n.doRaw(mappedConfig, "POST", fmt.Sprintf("builds/%d/artifacts?%s", config.ID, query.Encode()), pr, mpw.FormDataContentType(), headers)
log := logrus.WithFields(logrus.Fields{
"id": config.ID,
......@@ -300,7 +306,7 @@ func (n *GitLabClient) UploadArtifacts(config common.BuildCredentials, artifacts
}
baseName := filepath.Base(artifactsFile)
return n.UploadRawArtifacts(config, file, baseName)
return n.UploadRawArtifacts(config, file, baseName, "")
}
func (n *GitLabClient) DownloadArtifacts(config common.BuildCredentials, artifactsFile string) common.DownloadState {
......
......@@ -299,6 +299,11 @@ func (b *AbstractShell) uploadArtifacts(w ShellWriter, options *archivingOptions
args = append(args, "--name", name)
}
// Get artifacts:expire_in
if expire_in, ok := info.Build.Options.GetString("artifacts", "expire_in"); ok && expire_in != "" {
args = append(args, "--expire-in", expire_in)
}
w.Notice("Uploading artifacts...")
w.Command(info.RunnerCommand, args...)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment