The actual problem is that you run the script over sudo, which doesn’t preserve the proxy-related environment variables to allow network access.
As the build is already run as root dropping the sudo
call should work.
Refer: Launchpad build fails with "Could not resolve 'dl.bintray.com'"