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 [email protected]: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 [email protected]:X/Y.git"
sh "git remote -v"
sh "git push origin master"
sh "cat .git/config"
So the error states that theres already a remote with the same name. And sensibly you cant add that twice. A couple of options:
EDIT
Seems like a duplicate of: Github "fatal: remote origin already exists"