Jenkins and Google Cloud Platform Subnetwork should not be empty Error

Hello Everyone

I am trying out GCP for the first time. I have an instance of Jenkins set up on my laptop running Windows 10. I am trying to create a Jenkins pipeline that does a Java build and deploys it to GCP. When I try to run the build, I get the following error:

  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid value for field 'resource.networkInterfaces[0].subnetwork': ''. Subnetwork should not be empty.",
    "reason" : "invalid"
  } ],
  "message" : "Invalid value for field 'resource.networkInterfaces[0].subnetwork': ''. Subnetwork should not be empty."

Looking at the documentation, I discovered that the url for the subnetwork resource ought to have the form

it seems mine is missing the instance/subnetwork at the end. I think this is related to the fact that when I was configuring the Google Compute Engine in my local instance of Jenkins, The dropdown menu labelled “Machine Configuration Template to use” was always empty. I tried every allowable combination of the Region and Zone dropdown menus but the Template menu always came up blank. Please I would be extremely grateful on any pointers as to how to solve this problem.

Hi @imonike. It sounds like you’re trying to use a Jenkins plugin here, possibly the Google Compute Engine plugin. Is that the case?

If you are using the GCE plugin, I don’t think this is the right use case for the plugin. As I understand it, the GCE plugin is used for provisioning workers to run builds, not to provision machines to run the output of a build. Perhaps that’s where some of the issues are coming in?

Hello Michael. Thanks for the response.
Yes it is the GCE plugin I am trying to use here, and thank you for pointing out that I got the use case wrong. I was actually trying to follow this tutorial:

Though I had a wrong conception, since I was merely trying to follow a tutorial, whose authors I believe, would have the right conception, I think that there would be at least some issues that are independent of my wrong conception.
The Jenkins instance like I said earlier is running off my laptop. The tutorial mentioned that the jenkins instance could be in the cloud or on-premise. I interpreted that to mean that the jenkins instance could run outside GCP and so I thought running it off my laptop was fair game. I am mentioning this because I would like to know if you think this is an issue.
In the tutorial, there is a snapshot of the GUI for configuring the Jenkins instance. There happens to be a dropdown labelled Machine Configuration Template to use. In the snapshot it is currently set to the value jenkins-agent-1. When I am configuring my actual instance, this dropdown is always blank. I have tried all combos of region and zone but it always comes up blank. This is where I suspect the subnetwork should not be empty error is coming from but I am not sure.
Thank you for any other assistance you can render.

Hi @imonike. Unfortunately, that tutorial appears to leave out a crucial part of the configuration, which is creating the VM image that you will launch when a job requests it. It’s briefly alluded to with the following paragraph under Jenkins Cloud Setup:

Note: The instance requires java8 installed and on the default path. Create a VM, install Java8 and create a new OS image in your GCP project. Packer can also be used to achieve this. More info here.

Unfortunately, the “More info here” text isn’t a clickable link and I’m not sure how it gets set up as I’ve never used Google Cloud myself. The other thing is that that paragraph is likely out of date: you need to have the same version of Java installed on the VM as you are using to run Jenkins, which will be a minimum of Java 11 if you’re running Jenkins 2.357 weekly or Jenkins 2.361.1 LTS or later.

The templates dropdown is likely empty because the Jenkins plugin is querying Google Cloud using the service account you created and looking for any VM images that it can launch, but it’s not finding any. That would also prevent it from creating any agents using that configuration (as there’s nothing for it to launch).

1 Like

Wow. Thank you Michael. I really appreciate the drilling down. I will look into creating the VM image or achieving my goal by some other means. Thanks again. I am grateful.

1 Like

Sounds great, @imonike. Will be curious to hear if that resolves your issue!

@mtughan . Sorry I took so long to respond. You were right about the instance template. I still couldn’t get the Jenkins/GCP pipeline to work after creating the template. I have been struggling since then. I eventually abandoned that template and created a VM image using Packer while following some documentation on the cloud google site. I just got the pipeline to work yesterday. Thanks for your help.