simple check option

This commit is contained in:
anianz
2020-11-11 12:22:16 +01:00
parent b266699086
commit cbbfd94fbb
4 changed files with 67 additions and 17 deletions

View File

@@ -1,8 +1,13 @@
package common
import (
"bytes"
"encoding/json"
"fmt"
"os"
"os/exec"
resource "github.com/cioplenu/concourse-nomad-resource"
)
func Check(err error, msg string) {
@@ -11,3 +16,24 @@ func Check(err error, msg string) {
os.Exit(1)
}
}
func GetHistory(source resource.Source) []resource.JobVersion {
cmd := exec.Command(
"nomad",
"job",
"history",
"-json",
"-address="+source.URL,
"-token="+source.Token,
source.Name,
)
var histResp bytes.Buffer
cmd.Stdout = &histResp
err := cmd.Run()
Check(err, "Error checking versions")
var history []resource.JobVersion
json.Unmarshal(histResp.Bytes(), &history)
return history
}