You’ll have a better experience if you configure your repository to notify Jenkins whenever there is a change. That is usually done with webhooks. In many cases, an organization folder or a multibranch Pipeline may configure those webhooks automatically. You want to avoid polling for changes. As advised by Kohsuke Kawaguchi in 2011, “polling must die”.
If it were me, I’d create a command line script or program in my favorite scripting language. Once that command line script is working, I’d add a Jenkinsfile that calls the script. If the script needs credentials, have the Jenkinsfile pass them in using withCredentials.
I’d keep the Jenkinsfile as short and simple as possible because it is a lot easier to debug deployment failures from a development environment on my desktop than to repeatedly run the Jenkins job to debug failures.