Jenkins Pipeline Utility Steps zip zipFile is not creating proper apiproxy zip file.

Hi,

We are using Jenkins pipeline to make Apigee API calls for creating the apipoxy. Here is code for jenkins pipeline:

            steps {
                script {
                        // Inside apiproxy we have all the files and folders.
                         def directoryPath = "/apiproxy";          
                        zip zipFile: 'apiproxy.zip',archive: false, dir: directoryPath
 
                      sh '''
                       curl -X POST -u <credential> -H "content-type: multipart/form-data" -F "file=@apiproxy.zip"                           "http://<domain>/v1/organizations/<org>/apis?action=import&name=myproxy"
                       '''
                    }
            }
This call  zip zipFile: 'apiproxy.zip',archive: false, dir: directoryPath creates apiproxy.zip file on workspace. We are using aws linux slave for jobs. Here is error for pipleline output.
 
> POST /v1/organizations/<org>/apis?action=import&name=myproxy HTTP/1.1
> User-Agent: curl/7.29.0
> Accept: */*
> Content-Length: 1359
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------<number>
>
< HTTP/1.1 100 Continue
} [data not shown]
< HTTP/1.1 400 Bad Request
< X-Apigee.fault-code: messaging.config.beans.InvalidBundle
< Content-Type: application/json
< X-Apigee.backends: 
< Content-Length: 122
* HTTP error before end of send, stop sending
 
We can download the apiproxy.zip on windows but can't make curl command also from cmd prompt. It is sating  messaging.config.beans.InvalidBundle error. It shows zip has some issues.
 
We tried to create zip file using linux tar command but it is also failing in curl command using jenkins pipeline.
 
Please suggest.
 
Thanks

 

Solved Solved
0 13 2,650
2 ACCEPTED SOLUTIONS

Invalid bundle can mean ... lots of things. One possibility is that your bundle is referencing a policy that is not included in the bundle. Or maybe your bundle is missing a target endpoint. Another possibility is that one of your XML files is malformed.  

May I suggest that you run apigeelint on the bundle before uploading the bundle to the management server?   Apigeelint gives you clear error messages and warnings about such things, as well as many other style or usage problems. 

If you cannot do that, then, I suggest that you examine the full error message returned from the management server with the 400 status code.  Usually there is an error message that specifies exactly what the problem is.  If you cannot do that, ,then.... perhaps consult the system.log for the management server. I am guessing that you are using OPDK, from the http:// scheme on the management server URL. If you are using OPDK then you have access to the system.log of the management server and it may have a message there that describes the problem with the invalid bundle. 


@deepak-1 wrote:

It is sating  messaging.config.beans.InvalidBundle error. It shows zip has some issues.


 

Can you be SPECIFIC about "some issues"?   When you download the apiproxy.zip and try to upload it (==import it into Apigee, I guess) via a curl command, WHAT IS THE COMPLETE ERROR MESSAGE? If you run curl with the -i option, you will see the response payload with the error message. 

Or you can run apigeelint on that zip file. 

good luck

View solution in original post

GREAT. I'm glad to hear you resolved the problem. The correct structure for an API proxy zip bundle is, the folder apiproxy must be the containing directory for all assets. An example is here:

  Length      Date    Time    Name
---------  ---------- -----   ----
        0  10-17-2023 11:30   apiproxy/
      338  10-12-2023 13:52   apiproxy/name-of-api-proxy-here.xml
        0  10-17-2023 11:33   apiproxy/targets/
     1530  10-17-2023 11:33   apiproxy/targets/target-endpoint-here.xml
        0  10-17-2023 11:32   apiproxy/policies/
      373  10-09-2023 12:58   apiproxy/policies/policies-here.xml
      396  10-12-2023 15:00   apiproxy/policies/...
        0  10-17-2023 11:33   apiproxy/proxies/
     2759  10-17-2023 11:33   apiproxy/proxies/proxy-endpoint-here.xml

The documentation for this is here.

View solution in original post

13 REPLIES 13

Please provide an example of using tar command to prepare zip file and curl command to use it. It looks like I may be missing some headers. 

Invalid bundle can mean ... lots of things. One possibility is that your bundle is referencing a policy that is not included in the bundle. Or maybe your bundle is missing a target endpoint. Another possibility is that one of your XML files is malformed.  

May I suggest that you run apigeelint on the bundle before uploading the bundle to the management server?   Apigeelint gives you clear error messages and warnings about such things, as well as many other style or usage problems. 

If you cannot do that, then, I suggest that you examine the full error message returned from the management server with the 400 status code.  Usually there is an error message that specifies exactly what the problem is.  If you cannot do that, ,then.... perhaps consult the system.log for the management server. I am guessing that you are using OPDK, from the http:// scheme on the management server URL. If you are using OPDK then you have access to the system.log of the management server and it may have a message there that describes the problem with the invalid bundle. 


@deepak-1 wrote:

It is sating  messaging.config.beans.InvalidBundle error. It shows zip has some issues.


 

Can you be SPECIFIC about "some issues"?   When you download the apiproxy.zip and try to upload it (==import it into Apigee, I guess) via a curl command, WHAT IS THE COMPLETE ERROR MESSAGE? If you run curl with the -i option, you will see the response payload with the error message. 

Or you can run apigeelint on that zip file. 

good luck

Hi,

Thanks for your reply. Below is simple structure I am using.  Downloaded zip file is also giving the same error when using curl command on windows.

Here is curl command:

$ curl -i -X POST -u -H "content-type: multipart/form-data" -F "file=@Downloadapiproxy.zip" "http:///v1/organizations//apis?action=import&name=myproxywithoutdeploy"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2113 100 122 100 1991 346 5654 --:--:-- --:--:-- --:--:-- 6054HTTP/1.1 400 Bad Request
X-Apigee.fault-code: messaging.config.beans.InvalidBundle
Content-Type: application/json
Date: Mon, 16 Oct 2023 18:44:20 GMT
X-Apigee.backends:
X-Apigee.organization:
X-Apigee.user:
Content-Length: 122

{
"code" : "messaging.config.beans.InvalidBundle",
"message" : "Bundle is invalid. Empty bundle",
"contexts" : [ ]
}

 

proxies: default.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
<Description/>
<FaultRules/>
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
<Flows/>
<HTTPProxyConnection>
<BasePath>/myproxywithoutdeploy</BasePath>
<Properties/>
<VirtualHost>secure</VirtualHost>
</HTTPProxyConnection>
<RouteRule name="default">
<TargetEndpoint>default</TargetEndpoint>
</RouteRule>
</ProxyEndpoint>

targets: default.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
<Description/>
<FaultRules/>
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
<Flows/>
<HTTPTargetConnection>
<Properties/>
<URL>https://www.google.com</URL>
</HTTPTargetConnection>
</TargetEndpoint>

myproxywithoutdeploy.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<APIProxy revision="1" name="myproxywithoutdeploy">
<Basepaths>/myproxywithoutdeploy</Basepaths>
<Description>This is my proxy without deployment</Description>
<DisplayName>myproxywithoutdeploy</DisplayName>
<Policies/>
<ProxyEndpoints>
<ProxyEndpoint>default</ProxyEndpoint>
</ProxyEndpoints>
<Resources/>
<Spec></Spec>
<TargetServers/>
<TargetEndpoints>
<TargetEndpoint>default</TargetEndpoint>
</TargetEndpoints>
</APIProxy>

Please look.

 

Thanks

Deepak

 

 

 

 

Here is scenario: 

I have above same code on local. I can zip it using zip in window and run curl command, It is working fine. API call can create API Proxy on the server.

Now I am pushing same code to bitbucket where using Jenkins I am picking up the folder and creating zip file using below command:

zip zipFile: 'apiproxy.zip',archive: false, dir: path
Now zip file creates but API call fails as showing  error.
< X-Apigee.fault-code: messaging.config.beans.InvalidBundle
 
If i download same zip from the workspace it shows the same error on local. And I have verified contents are there.
 
Thanks
Deepak

 

file2.PNGfile1.PNGDirectoryStructure.PNGfile3.PNG

Please see the folder structure.

Thanks for looking into it. We found out the created zip was not having apiproxy root folder instead proxies,targets etc. 

So we created zip with apiproxy as root folder.

 

Thanks

Deepak

GREAT. I'm glad to hear you resolved the problem. The correct structure for an API proxy zip bundle is, the folder apiproxy must be the containing directory for all assets. An example is here:

  Length      Date    Time    Name
---------  ---------- -----   ----
        0  10-17-2023 11:30   apiproxy/
      338  10-12-2023 13:52   apiproxy/name-of-api-proxy-here.xml
        0  10-17-2023 11:33   apiproxy/targets/
     1530  10-17-2023 11:33   apiproxy/targets/target-endpoint-here.xml
        0  10-17-2023 11:32   apiproxy/policies/
      373  10-09-2023 12:58   apiproxy/policies/policies-here.xml
      396  10-12-2023 15:00   apiproxy/policies/...
        0  10-17-2023 11:33   apiproxy/proxies/
     2759  10-17-2023 11:33   apiproxy/proxies/proxy-endpoint-here.xml

The documentation for this is here.

Thank you.

I am able to create API proxy with zip file with single API call.

I have read https://www.googlecloudcommunity.com/gc/Apigee/API-proxy-creation-through-management-API/m-p/40795#M... for multiple API calls with content type application/xml.

Can you please guide if we have documentation for content-type application/json format for each request? I would like to call individual apis with json data. I am not able to figure out correct format of post data.

Please look into it.

The collections that allow you to create a policy, or create an endpoint, etc, are not supported in Apigee X or hybrid. You cannot update individual policies or create endpoints, step by step, with different REST calls in Apigee X or in Apigee hybrid. The only way to get a proxy into Apigee X or hybrid is to import a bundle. REST API doc here. Or you can use the apigeecli tool like this:

 

apigeecli apis create bundle -f ./path/to/apiproxy --name name-of-my-api-proxy -o $ORG --token $TOKEN

Regarding the collections that are described in the older community post you cited, even though they work on the older Apigee Edge, it's probably a poor idea to use them, at this point.  A better way is to generate the proxy from a template, using something like this. And then import the proxy bundle with the apigeecli tool (if X or hybrid), or  some other tool like importAndDeploy.js

To get the CLI tool on your build server you can do this: 

curl -s https://raw.githubusercontent.com/apigee/apigeecli/master/downloadLatest.sh | bash
export PATH=$PATH:$HOME/.apigeecli/bin

 

Thank you very much for your suggestion and guidance. 

@dchiesa1 - We are using Apigee Edge. Please let me know if we can make individual API calls with json Post data.  

It would be helpful if you can provide examples or some documentations.

Thanks

 

Hi Deepak, 

is this a new question?  I'm not able to make sense of it.  Missing some context maybe.  I thought you were asking, "how can I create a bundle"?   and I think you resolved that.  I don't get your new question, or how it relates to the original one.  

If this is a new q, just ask a new one, and post details and context to explain what you are aiming for.

Hi dchiesa1

My bad I will open a new question.

Thanks