simple check option
This commit is contained in:
		@@ -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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user