Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion services/tasks/LocalJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package tasks
import (
"encoding/json"
"fmt"
"github.com/semaphoreui/semaphore/pkg/ssh"
"maps"
"os"
"strings"

"github.com/semaphoreui/semaphore/pkg/ssh"

"path"
"strconv"

Expand Down Expand Up @@ -64,6 +65,9 @@ func (t *LocalJob) SetStatus(status task_logger.TaskStatus) {
}

func (t *LocalJob) SetCommit(hash, message string) {
// TODO: is this the correct place to do?
t.Task.CommitHash = &hash
t.Task.CommitMessage = message
t.Logger.SetCommit(hash, message)
}

Expand All @@ -88,6 +92,12 @@ func (t *LocalJob) getEnvironmentExtraVars(username string, incomingVersion *str

taskDetails["username"] = username
taskDetails["url"] = t.Task.GetUrl()
taskDetails["commit_hash"] = t.Task.CommitHash
taskDetails["commit_message"] = t.Task.CommitMessage
taskDetails["inventory_name"] = t.Inventory.Name
taskDetails["inventory_id"] = t.Inventory.ID
taskDetails["repository_name"] = t.Repository.Name
taskDetails["repository_id"] = t.Repository.ID

if t.Template.Type != db.TemplateTask {
taskDetails["type"] = t.Template.Type
Expand Down Expand Up @@ -136,6 +146,12 @@ func (t *LocalJob) getEnvironmentExtraVarsJSON(username string, incomingVersion

taskDetails["username"] = username
taskDetails["url"] = t.Task.GetUrl()
taskDetails["commit_hash"] = t.Task.CommitHash
taskDetails["commit_message"] = t.Task.CommitMessage
taskDetails["inventory_name"] = t.Inventory.Name
taskDetails["inventory_id"] = t.Inventory.ID
taskDetails["repository_name"] = t.Repository.Name
taskDetails["repository_id"] = t.Repository.ID

if t.Template.Type != db.TemplateTask {
taskDetails["type"] = t.Template.Type
Expand Down
6 changes: 3 additions & 3 deletions services/tasks/TaskRunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func TestTaskGetPlaybookArgs(t *testing.T) {
}

res := strings.Join(args, " ")
if res != "-i /tmp/project_0/inventory_0 --extra-vars {\"semaphore_vars\":{\"task_details\":{\"id\":0,\"url\":null,\"username\":\"\"}}} test.yml" {
if res != "-i /tmp/project_0/inventory_0 --extra-vars {\"semaphore_vars\":{\"task_details\":{\"commit_hash\":null,\"commit_message\":\"\",\"id\":0,\"inventory_id\":0,\"inventory_name\":\"\",\"repository_id\":0,\"repository_name\":\"\",\"url\":null,\"username\":\"\"}}} test.yml" {
t.Fatal("incorrect result")
}
}
Expand Down Expand Up @@ -623,7 +623,7 @@ func TestTaskGetPlaybookArgs2(t *testing.T) {
}

res := strings.Join(args, " ")
if res != "-i /tmp/project_0/inventory_0 --extra-vars {\"semaphore_vars\":{\"task_details\":{\"id\":0,\"url\":null,\"username\":\"\"}}} test.yml" {
if res != "-i /tmp/project_0/inventory_0 --extra-vars {\"semaphore_vars\":{\"task_details\":{\"commit_hash\":null,\"commit_message\":\"\",\"id\":0,\"inventory_id\":0,\"inventory_name\":\"\",\"repository_id\":0,\"repository_name\":\"\",\"url\":null,\"username\":\"\"}}} test.yml" {
t.Fatal("incorrect result")
}
}
Expand Down Expand Up @@ -680,7 +680,7 @@ func TestTaskGetPlaybookArgs3(t *testing.T) {
}

res := strings.Join(args, " ")
if res != "-i /tmp/project_0/inventory_0 --extra-vars {\"semaphore_vars\":{\"task_details\":{\"id\":0,\"url\":null,\"username\":\"\"}}} test.yml" {
if res != "-i /tmp/project_0/inventory_0 --extra-vars {\"semaphore_vars\":{\"task_details\":{\"commit_hash\":null,\"commit_message\":\"\",\"id\":0,\"inventory_id\":0,\"inventory_name\":\"\",\"repository_id\":0,\"repository_name\":\"\",\"url\":null,\"username\":\"\"}}} test.yml" {
t.Fatal("incorrect result")
}
}
Expand Down
Loading