Issue:
When building your app using BrowserStack your build fails with an UnknownHostException error:
java.net.UnknownHostException: prd-20-04-usc1b-220309133144-sny9nhmtmjrqxdjxrupapg: prd-20-04-usc1b-2203091222144-snyasdnhmtmjrqxdjxrupapg: Name or service not known
Possible Solutions:
To fix this issue, you should change the default DNS server to Google’s DNS server, 8.8.8.8. This way, Java can use it to resolve the host every time.
To change the DNS server to 8.8.8.8, include the following in a Script Step:
networksetup -setdnsservers Ethernet 8.8.8.8
You should clear your DNS cache to ensure your old DNS address is no longer in use. To do so, add:
networksetup -getdnsservers Ethernet
Finally, to verify that the change was successful, you can print the current DNS server with the following script:
scutil --dns
Add the Script Step to your Workflow before any Steps that use BrowserStack.
Combining the information from above, the Script Step should look like this:
steps:
- script@1:
inputs:
- content: |-
#!/usr/bin/env bash
# fail if any commands fails
set -e
# make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
set -o pipefail
# debug log
set -x networksetup -setdnsservers Ethernet 8.8.8.8
networksetup -getdnsservers Ethernet
scutil --dns