Skip to content

Commit

Permalink
Added ${PROJECT_SERVERS}
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenorzz committed Aug 18, 2024
1 parent c37441f commit 7dd1194
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/server/task/deploy/local_script_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (gsync *Gsync) runLocalScript() error {
}
scriptText := commitInfo.ReplaceVars(content)
scriptText = project.ReplaceVars(scriptText)
scriptText = gsync.ProjectServers.ReplaceVars(scriptText)
scriptText = project.ReplaceCustomVars(scriptText)

// run yaml script by docker
Expand Down
11 changes: 11 additions & 0 deletions internal/model/project_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package model

import (
"encoding/json"
"fmt"
"strings"

Expand Down Expand Up @@ -212,6 +213,16 @@ func (ps ProjectServer) ReplaceVars(script string) string {
return ps.Server.ReplaceVars(script)
}

func (ps ProjectServers) ReplaceVars(script string) string {
var servers []Server
for _, p := range ps {
servers = append(servers, p.Server)
}
serverJson, _ := json.Marshal(servers)
script = strings.Replace(script, "${PROJECT_SERVERS}", string(serverJson), -1)
return script
}

// Note that doubling a single-quote inside a single-quoted string gives you a single-quote
// see `man rsync`
func quote(s string) string {
Expand Down
8 changes: 8 additions & 0 deletions web/src/views/project/manage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@
formData.label !== '' ? formData.label : 'project.label'
}}</span>
</el-row>
<el-row>
<span>${PROJECT_SERVERS}: </span>
<span>JSON format</span>
</el-row>
<el-row>
<span>${REPOSITORY_TYPE}: </span>
<span>{{
Expand Down Expand Up @@ -1025,6 +1029,10 @@
formData.label !== '' ? formData.label : 'project.label'
}}</span>
</el-row>
<el-row>
<span>${PROJECT_SERVERS}: </span>
<span>JSON format</span>
</el-row>
<el-row>
<span>${REPOSITORY_TYPE}: </span>
<span>{{
Expand Down

0 comments on commit 7dd1194

Please sign in to comment.