Install Openjdk8 using brew in GitLab CI MacOS prompt for password

I’m trying to install adoptopenjdk8 on a mac machine using GitLab CI’s shell executor. This is the command that I used for installing the sdk:

brew install --cask homebrew/cask-versions/adoptopenjdk8

In that case, it is asking for a password for the installation. So I used ‘sudo -v’ command to cache the sudo password.

echo $PASSWORD | sudo -vS
brew install --cask homebrew/cask-versions/adoptopenjdk8

By this method, it worked from the terminal. The openjdk was installed without prompting for password.
But when I ran this command in gitlab ci, it is prompting for password and the job fails. How can I bypass the password prompt?