https://linen.dev logo
Title
m

Manan Girdhar

01/30/2023, 9:26 AM
I just wanted to know can we run wiremock on local machine instead of running it on a server. currently we are running wiremocks to automate different security tools on jenkins server. but we are not able to run the same setup on our local machine.
r

Rob Elliot

01/30/2023, 10:25 AM
You'll need a JRE installed, but then you should just be able to follow this: https://wiremock.org/docs/running-standalone/
m

Manan Girdhar

01/30/2023, 10:32 AM
can the same code work on both jenkins as well as local?
r

Rob Elliot

01/30/2023, 10:33 AM
I don't really understand the question - in principal yes? But it depends what code you mean.
m

Manan Girdhar

01/30/2023, 10:37 AM
I mean the code I used for running it on jenkins can the same code be used to run it on local?? or do I need some changes
org.eclipse.jetty.util.log.StdErrLog logger = new org.eclipse.jetty.util.log.StdErrLog();
        logger.setLevel(org.eclipse.jetty.util.log.StdErrLog.LEVEL_OFF);
        org.eclipse.jetty.util.log.Log.setLog(logger);

        wireMockServer = new WireMockServer(options().usingFilesUnderDirectory(getDirectoryLocation(toolName)).port(randomWiremockPort())); //No-args constructor will start on port 8080, no HTTPS 
       wireMockServer.start();
r

Rob Elliot

01/30/2023, 10:38 AM
Yes, you can run that code locally. I think most people run tests that start and stop WireMock locally.
m

Manan Girdhar

01/30/2023, 10:38 AM
ok thanks
and what will be the api endpoint when running locally. we also run that using ssh where the endpoint is the server IP and when we run on jenkins the endpoint is the jenkins endpoint, but what will be the endpoint when we run on local?
r

Rob Elliot

01/30/2023, 10:46 AM
It will be
<http://localhost>:<random_port>
because you are using
.port(randomWiremockPort())
- I think
randomWiremockPort()
must be your own logic, it's not a WireMock function.
The WireMock equivalent is
options().dynamicPort()
. You can get the port from WireMock -
wireMockServer.port()
will return it so you can print it.
Are you able to share more details about the use case? We'd love to go on a short call to understand what you are doing.
m

Manan Girdhar

02/07/2023, 6:29 AM
we use it to test the security tools that are integrated into our platform, our test cases run fine on Jenkins but somehow not able to run on http://localhost:<random_port>.