使用Azure Batch作为Jenkins的节点 [英] use Azure Batch as Jenkins' node

查看:67
本文介绍了使用Azure Batch作为Jenkins的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jenkins服务器,该服务器与其他计算机作为节点运行良好.我也有一个Azure Batch帐户和一个工作池.有没有办法将两者连接在一起,以便将Jenkins任务发送到Azure批处理池?

I have a Jenkins server that is running well with other machines as node. I have also a Azure Batch account and a working pool. Is there a way to connect both so that Jenkins tasks are sent to the Azure Batch pool?

到目前为止,我只找到了这个 https://github.com/Azure/batch-jenkins 是用于并行执行测试的构建后插件,这不是我想要的.我只需要向Azure发送命令行.

So far I have only found this https://github.com/Azure/batch-jenkins that is a post-build plugin to execute tests in parallel, that's not what I am looking for. I just need to send a command line to Azure.

谢谢

推荐答案

由于您的要求是向Azure发送命令行,所以我建议您有一个简单的Jenkins作业(自由式作业或管道作业)即可完成要求.

As your requirement is to send a command line to Azure so I would suggest you to have a simple Jenkins job (either freestyle job or pipeline job) which would accomplish the requirement.

先决条件:

  1. 拥有一个Azure批处理帐户
  2. 具有Azure批处理池
  3. 具有Azure批处理作业
  4. Azure CLI安装在要运行Jenkins作业的Jenkins节点中
  5. 按照指示然后有一个Jenkins自由式作业,在使用Azure服务主体连接到Azure CLI之后,在shell生成步骤中执行类似于下面的命令.

    Then have a Jenkins freestyle job executing commands similar to below one in shell build step after connecting to Azure CLI using Azure service principal.

    az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID
    
    az batch task create --task-id mytask$i --job-id myjob --command-line "/bin/bash -c 'xxxxxxxxxxxxxxxxxxxxx; sleep 90s'"
    

    或者有一个Jenkins管道作业,如下所示.

    Or else have a Jenkins pipeline job something like shown below.

    #!groovy
    node {
        try {
            xxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxx
        }
        catch (MissingPropertyException e) {
            xxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxx
        }
        stage('test'){
            withCredentials([azureServicePrincipal('JENKINSSERVICEPRINCIPALCREDENTIALID')]) {
                def sampleoutputone = sh (returnStdout: true, script: '''az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID > /dev/null
                az account set -s $AZURE_SUBSCRIPTION_ID > /dev/null
                sampleoutputtwo=$(az batch task create --task-id mytask --job-id myjob --command-line "/bin/bash -c 'xxxxxxxxxxxxxxxxxxxxx; sleep 90s'")
                xxxxxxxxxxxxxxxxxxxxx
                xxxxxxxxxxxxxxxxxxxxx
            }
        }
    }
    

    P.S.请注意,此答案中提供的代码只是一个示例,您可能需要根据需要对其进行一些调整.

    P.S. Note that the code provided in this answer is just a sample one which you may have to tweak a bit to work as per your needs.

    希望这会有所帮助!!干杯!

    Hope this helps!! Cheers!!

    这篇关于使用Azure Batch作为Jenkins的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆