Jenkins git触发了build而不是阻塞

时间:2016-09-06 18:05:08

标签: python amazon-web-services jenkins

我在我的jenkins服务器上运行构建于public partial class ImageCopier : Form { private BackgroundWorker backgroundWorker = new BackgroundWorker(); public ImageCopier() { InitializeComponent(); //backgroundWorker.DoWork += Copier_DoWork; } private void Form1_Load(object sender, EventArgs e) { string[] accounts = Directory.GetDirectories("photolocation", "???").Select(d => new DirectoryInfo(d).Name).ToArray(); accountBox.Items.AddRange(accounts); } private void copyButton_Click(object sender, EventArgs e) { if (accountBox.SelectedItems.Count == 0) { MessageBox.Show("You must select an account."); } else { for (int i = 0; i < accountBox.SelectedItems.Count; i++) { MessageBox.Show("Starting on account " + accountBox.SelectedItems[i]); for (int a = 0; a <= 9; a++) { directoryLabel.Text = "In Folder " + a.ToString(); directoryLabel.Refresh(); string[] files = Directory.GetFiles("photolocation" + accountBox.SelectedItems[i] + "\\photos\\" + a + "\\"); files = files.Where(f => f.Contains('$') != true).ToArray(); if (files.Count() != 0) { for (int b = 0; b < files.Count(); b++) { fileLabel.Text = "File " + (b + 1) + " of " + files.Count().ToString(); fileLabel.Refresh(); File.Copy(files[b], files[b].Replace("photolocation", "altlocation"), true); } } else { MessageBox.Show("Computer does not have read access to image server or there are no photos."); } } MessageBox.Show("Finished account " + accountBox.SelectedItems[i]); } //backgroundWorker.RunWorkerAsync(); } } private void Copier_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; i < accountBox.SelectedItems.Count; i++) { MessageBox.Show("Starting on account " + accountBox.SelectedItems[i]); for (int a = 0; a <= 9; a++) { directoryLabel.Text = "In Folder " + a.ToString(); directoryLabel.Refresh(); string[] files = Directory.GetFiles("photolocation" + accountBox.SelectedItems[i] + "\\photos\\" + a + "\\"); files = files.Where(f => f.Contains('$') != true).ToArray(); if (files.Count() != 0) { for (int b = 0; b < files.Count(); b++) { //fileLabel.Text = "File " + (b + 1) + " of " + files.Count().ToString(); //fileLabel.Refresh(); File.Copy(files[b], files[b].Replace("photolocation", "altlocation"), true); } } else { MessageBox.Show("Computer does not have read access to image server or there are no photos."); } } MessageBox.Show("Finished account " + accountBox.SelectedItems[i]); } } } 的提交,该服务器正在为Amazon AWS部署资源。我正在使用Execute Shell部分来运行一个处理所有单元测试/ linting / validation / deployment的python脚本,所有内容都会很好地阻塞,直到它进入部署(origin/master),然后在启动后立即返回成功,但是没有完成部署。我怎么能做这个块?

这里的参考是我的配置:

执行Shell(Jenkins)

deploy.deploy()

kickoff.py

export DEPLOY_REGION=us-west-2
. build-tools/get_aws_credentials.sh
python build-tools/kickoff.py

deploy.py

if __name__ == "__main__":
    build_tools_dir="{}".format("/".join(os.path.abspath(__file__).split("/")[0:-1]))
    sys.path.append(build_tools_dir)
    base_dir = "/".join(build_tools_dir.split("/")[0:-1])
    test_begin = __import__("test_begin")
    test_all_templates = __import__("test_all_templates")
    deploy = __import__("deploy")
    git_plugin = __import__("git_plugin")
    retval = test_begin.entrypoint("{}/platform/backend".format(base_dir))
    if (retval == "SUCCESS"):
        retval = test_all_templates.entrypoint("{}/platform/backend".format(base_dir))
        if (retval == "SUCCESS"):
            deploy.deploy()

1 个答案:

答案 0 :(得分:0)

您可以使用api调用aws来检索状态并等到它变为某种状态&#39;。

下面的例子是伪代码来说明这个想法:

import time
import boto3
ec2 = boto3.resource('ec2')

while True:
    response = ec2.describe_instance_status(.....)
    if response == 'some status':
        break
    time.sleep(60)

# continue execution