Commit fe798d37 authored by Kamil Trzciński's avatar Kamil Trzciński

Added support for custom variables received from CI

parent 401b7b0f
v 0.4.0
- Added CI=true and GITLAB_CI=true to environment variables
- Added output_limit (in kilobytes) to runner config which allows to enlarge default build log size
- Added support for custom variables received from CI
- Make the debug log human readable
- Make default build log limit set to 4096 (4MB)
- Updated kardianos service to fix OSX service installation
......
......@@ -35,16 +35,22 @@ type GetBuildRequest struct {
Token string `json:"token,omitempty"`
}
type BuildVariable struct {
Key string `json:"key"`
Value string `json:"value"`
}
type GetBuildResponse struct {
ID int `json:"id,omitempty"`
ProjectID int `json:"project_id,omitempty"`
Commands string `json:"commands,omitempty"`
RepoURL string `json:"repo_url,omitempty"`
Sha string `json:"sha,omitempty"`
RefName string `json:"ref,omitempty"`
BeforeSha string `json:"before_sha,omitempty"`
AllowGitFetch bool `json:"allow_git_fetch,omitempty"`
Timeout int `json:"timeout,omitempty"`
ID int `json:"id,omitempty"`
ProjectID int `json:"project_id,omitempty"`
Commands string `json:"commands,omitempty"`
RepoURL string `json:"repo_url,omitempty"`
Sha string `json:"sha,omitempty"`
RefName string `json:"ref,omitempty"`
BeforeSha string `json:"before_sha,omitempty"`
AllowGitFetch bool `json:"allow_git_fetch,omitempty"`
Timeout int `json:"timeout,omitempty"`
Variables []BuildVariable `json:"variables"`
}
type RegisterRunnerRequest struct {
......
package shells
import (
"fmt"
. "gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
)
type AbstractShell struct {
}
func (s *AbstractShell) GetDefaultVariables(build *Build, projectDir string) []string {
return []string{
fmt.Sprintf("CI_BUILD_REF=%s", build.Sha),
fmt.Sprintf("CI_BUILD_BEFORE_SHA=%s", build.BeforeSha),
fmt.Sprintf("CI_BUILD_REF_NAME=%s", build.RefName),
fmt.Sprintf("CI_BUILD_ID=%d", build.ID),
fmt.Sprintf("CI_BUILD_REPO=%s", build.RepoURL),
fmt.Sprintf("CI_PROJECT_ID=%d", build.ProjectID),
fmt.Sprintf("CI_PROJECT_DIR=%s", projectDir),
"CI=true",
"CI_SERVER=yes",
"CI_SERVER_NAME=GitLab CI",
"CI_SERVER_VERSION=",
"CI_SERVER_REVISION=",
"GITLAB_CI=true",
}
}
func (s *AbstractShell) GetBuildVariables(build *Build) []string {
var variables []string
for _, variable := range build.Variables {
variables = append(variables,
fmt.Sprintf("%s=%s", variable.Key, variable.Value))
}
return variables
}
func (s *AbstractShell) GetVariables(build *Build, projectDir string) []string {
variables := s.GetDefaultVariables(build, projectDir)
variables = append(variables, s.GetBuildVariables(build)...)
return variables
}
......@@ -12,6 +12,7 @@ import (
)
type BashShell struct {
AbstractShell
}
func (b *BashShell) GetName() string {
......@@ -81,27 +82,8 @@ func (b *BashShell) GenerateScript(build *common.Build, shellType common.ShellTy
w.Flush()
env := []string{
fmt.Sprintf("CI_BUILD_REF=%s", build.Sha),
fmt.Sprintf("CI_BUILD_BEFORE_SHA=%s", build.BeforeSha),
fmt.Sprintf("CI_BUILD_REF_NAME=%s", build.RefName),
fmt.Sprintf("CI_BUILD_ID=%d", build.ID),
fmt.Sprintf("CI_BUILD_REPO=%s", build.RepoURL),
fmt.Sprintf("CI_PROJECT_ID=%d", build.ProjectID),
fmt.Sprintf("CI_PROJECT_DIR=%s", projectDir),
"CI=true",
"CI_SERVER=yes",
"CI_SERVER_NAME=GitLab CI",
"CI_SERVER_VERSION=",
"CI_SERVER_REVISION=",
"GITLAB_CI=true",
}
script := common.ShellScript{
Environment: env,
Environment: b.GetVariables(build, projectDir),
Script: buffer.String(),
Command: "bash",
}
......
......@@ -12,6 +12,7 @@ import (
)
type CmdShell struct {
AbstractShell
}
func (b *CmdShell) GetName() string {
......@@ -93,27 +94,8 @@ func (b *CmdShell) GenerateScript(build *common.Build, shellType common.ShellTyp
w.Flush()
env := []string{
fmt.Sprintf("CI_BUILD_REF=%s", build.Sha),
fmt.Sprintf("CI_BUILD_BEFORE_SHA=%s", build.BeforeSha),
fmt.Sprintf("CI_BUILD_REF_NAME=%s", build.RefName),
fmt.Sprintf("CI_BUILD_ID=%d", build.ID),
fmt.Sprintf("CI_BUILD_REPO=%s", build.RepoURL),
fmt.Sprintf("CI_PROJECT_ID=%d", build.ProjectID),
fmt.Sprintf("CI_PROJECT_DIR=%s", projectDir),
"CI=true",
"CI_SERVER=yes",
"CI_SERVER_NAME=GitLab CI",
"CI_SERVER_VERSION=",
"CI_SERVER_REVISION=",
"GITLAB_CI=true",
}
script := common.ShellScript{
Environment: env,
Environment: b.GetVariables(build, projectDir),
Script: buffer.String(),
Command: "cmd",
Arguments: []string{"/Q", "/C"},
......
......@@ -11,6 +11,7 @@ import (
)
type PowerShell struct {
AbstractShell
}
func (b *PowerShell) GetName() string {
......@@ -91,27 +92,8 @@ func (b *PowerShell) GenerateScript(build *common.Build, shellType common.ShellT
w.Flush()
env := []string{
fmt.Sprintf("CI_BUILD_REF=%s", build.Sha),
fmt.Sprintf("CI_BUILD_BEFORE_SHA=%s", build.BeforeSha),
fmt.Sprintf("CI_BUILD_REF_NAME=%s", build.RefName),
fmt.Sprintf("CI_BUILD_ID=%d", build.ID),
fmt.Sprintf("CI_BUILD_REPO=%s", build.RepoURL),
fmt.Sprintf("CI_PROJECT_ID=%d", build.ProjectID),
fmt.Sprintf("CI_PROJECT_DIR=%s", projectDir),
"CI=true",
"CI_SERVER=yes",
"CI_SERVER_NAME=GitLab CI",
"CI_SERVER_VERSION=",
"CI_SERVER_REVISION=",
"GITLAB_CI=true",
}
script := common.ShellScript{
Environment: env,
Environment: b.GetVariables(build, projectDir),
Script: buffer.String(),
Command: "powershell",
Arguments: []string{"-noprofile", "-noninteractive", "-executionpolicy", "Bypass", "-command"},
......
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