Trigger Jenkins job remotely from Azure Functions / Azure VM

匆匆过客 提交于 2021-01-29 05:26:22

问题


Am pretty new with Jenkins and just simply can't get this to work. I have been browsing the net for an answer but have not found an answer, or might not have understood what I should do.

I have Jobs in Jenkins that are currently scheduled (Python scripts). But one of these needs to be converted to be triggered remotely via URL. This I have been able to achieve and everything works fine when I am using the URL to trigger the Job from within our network at the office (Python, CMD, Browser, Postman etc).

However, when using this same URL to trigger the Job from Azure Functions or Azure VM, the Job is not being triggered (different IP - I believe this has to be the issue). I have been trying to open up the port 8080 on the machine currently running our Jenkins server by altering the Firewall settings, but regardless the HTTP POST isn't coming through. Triggering the Job from Azure Functions would be the goal.

Is there something obvious I am missing here in regards to Jenkins or is it just simply the fact that our Firewall is blocking the connection as we need to use VPN to connect into our local network from the outside. We only have set up Jenkins on one computer (a computer running within our local network) and have not introduced any slave nodes.


回答1:


This indeed does sound like a Firewall problem. There are quite a few ways to achieve such on-premise implementations in Azure without opening up your network to the outside.

Starting with the simplest approach


A. Logic Apps

Logic Apps because of its support for the On-Premises Data Gateway which allows it to access data from on-premises systems.

This has a couple of components to it

  1. Custom Connector You would have to create a custom connector which can connect via on-premises data gateway and have one action defined which can call your Jenkins machine

  2. Setup On-Premise Data Gateway
    You would have to setup the on-premises data gateway on your local network so that it has access to your Jenkins master (can be on the same host as the Jenkins master too)

  3. Create a Logic App
    This is the easy part where you use a Logic App instead of Function App. You can create a simple HTTP triggered Logic App which uses the Custom Connector that you created to trigger the Jenkins job


B. Azure Automation

Azure Automation has a similar feature wherein you can deploy a Hybrid Worker in your on-premises network and schedule jobs into that worker.

You could deploy either of the following workers based on your requirement

  1. Windows Worker
  2. Linux Worker

The runbook that you would write could be either in PowerShell or Python and its purpose would be to just call the Jenkins API to start the job.

With all this in place, you would just have to start the runbook on the hybrid worker.

You could also start a runbook from a webhook as well.


C. Connect your On-Premise network to Azure

This is more of a networking solution wherein you connect your on-premise network to an Azure VNET, allowing any resources in that VNET to access your on-premise systems.

There are a couple of ways you can achieve this as described in the documentation

  1. VPN Gateway
  2. Express Route

I won't go deep on how these are setup here. You can refer the documentation for detailed instructions on setting things up.

Once setup, you could either

  • Expose Jenkins
    For this you could simple just open a port on your VNET's NSG but this really isn't recommended I guess, since you might as well just expose it on your on-premises network directly instead.

    The preferred way would be to setup and use an Azure Application Gateway which is basically a reverse proxy.

  • Deploy your Function or Logic App into the VNET
    If you don't want to expose your Jenkins endpoint to the outside, you could deploy either

    • Function App into App Service Environment (ASE)
    • Logic App into Integration Service Environment (ISE)

    In both of these scenarios, you could directly call the Jenkins endpoint using the IP where its hosted (the on-premise IP itself)



来源:https://stackoverflow.com/questions/55236029/trigger-jenkins-job-remotely-from-azure-functions-azure-vm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!