本文整理汇总了Golang中github.com/jkellerer/jenkins-client-launcher/launcher/util.Config.CIClient方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.CIClient方法的具体用法?Golang Config.CIClient怎么用?Golang Config.CIClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jkellerer/jenkins-client-launcher/launcher/util.Config
的用法示例。
在下文中一共展示了Config.CIClient方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: downloadJar
func (self *JenkinsClientDownloader) downloadJar(config *util.Config) error {
util.GOut("DOWNLOAD", "Getting latest Jenkins client %v", (config.CIHostURI + "/" + ClientJarURL))
// Create the HTTP request.
request, err := config.CIRequest("GET", ClientJarURL, nil)
if err != nil {
return err
}
if fi, err := os.Stat(ClientJarName); err == nil {
request.Header.Add("If-Modified-Since", fi.ModTime().Format(http.TimeFormat))
}
// Perform the HTTP request.
var source io.ReadCloser
sourceTime := time.Now()
if response, err := config.CIClient().Do(request); err == nil {
defer response.Body.Close()
source = response.Body
if response.StatusCode == 304 {
util.GOut("DOWNLOAD", "Jenkins client is up-to-date, no need to download.")
return nil
} else if response.StatusCode != 200 {
return fmt.Errorf("Failed downloading jenkins client. Cause: HTTP-%v %v", response.StatusCode, response.Status)
}
if value := response.Header.Get("Last-Modified"); value != "" {
if time, err := http.ParseTime(value); err == nil {
sourceTime = time
}
}
} else {
return fmt.Errorf("Failed downloading jenkins client. Connect failed. Cause: %v", err)
}
target, err := os.Create(ClientJarDownloadName)
defer target.Close()
if err != nil {
return fmt.Errorf("Failed downloading jenkins client. Cannot create local file. Cause: %v", err)
}
if _, err = io.Copy(target, source); err == nil {
target.Close()
if err = os.Remove(ClientJarName); err == nil || os.IsNotExist(err) {
if err = os.Rename(ClientJarDownloadName, ClientJarName); err == nil {
os.Chtimes(ClientJarName, sourceTime, sourceTime)
}
}
return err
} else {
return fmt.Errorf("Failed downloading jenkins client. Transfer failed. Cause: %v", err)
}
}
示例2: invokeSystemGC
func (self *FullGCInvoker) invokeSystemGC(config *util.Config) {
// curl -d "script=System.gc()" -X POST http://user:[email protected]/ci/computer/%s/scriptText
postBody := strings.NewReader(fmt.Sprintf(FullGCPostBody, url.QueryEscape(FullGCScript)))
request, err := config.CIRequest("POST", fmt.Sprintf(FullGCURL, config.ClientName), postBody)
if err == nil {
if response, err := config.CIClient().Do(request); err == nil {
response.Body.Close()
if response.StatusCode != 200 {
util.GOut("gc", "ERROR: Failed invoking full GC as node request in Jenkins failed with %s", response.Status)
}
} else {
util.GOut("gc", "ERROR: Failed invoking full GC as Jenkins cannot be contacted. Cause: %v", err)
}
}
}