I am attempting to move a declarative pipeline from being written in a Jenkins Pipeline Configuration input box, to code hosted in BitBucket so that we have source control for any changes we make to this pipeline.
Due to the pipeline as code steps being written in a Jenkinsfile in a git repository, when I try to initialise a git repository to add my generated files to, I get an error:
+ git remote add origin git@bitbucket.org:X/Y.git
fatal: remote origin already exists.
Is there any way to handle this properly?
Edit:
sh "git init"
sh "git add ."
sh "git commit -m \"Initial commit\""
sh "git remote rm origin"
sh "git remote add origin git@bitbucket.org:X/Y.git"
sh "git remote -v"
sh "git push origin master"
sh "cat .git/config"