Hi all,
I'm trying to automate the 'copy script' functionality in ScriptRunner.
To be more specific - I want to be able to tell ScriptRunner to use 'copy script' and tell it which template to copy and create a new project.
The post here shows that @Phillip Ponzer _Cprime_ was able to write a bash script and execute it: https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-Call-Canned-Builtin-Script-Runner-Scripts-from-a-Script/qaq-p/466583
#!/bin/bash
USERNAME=my_username
PASSWORD=my_password
JIRA_URL=http://my.jira.instance.com
COOKIES=cookies.txt
HEADER="X-Atlassian-Token: no-check"
echo Logging in...
curl -s -c "$COOKIES" -H "$HEADER" -d "os_username=$USERNAME" -d "os_password=$PASSWORD" -d "os_cookie=true" $JIRA_URL/login.jsp --output login.html
echo Authenticating as administrator...
curl -si -c "$COOKIES" -b "$COOKIES" -H "$HEADER" -d "webSudoPassword=$PASSWORD" -d "os_cookie=true" -d "webSudoIsPost=false" -d "authenticate=Confirm" $JIRA_URL/secure/admin/WebSudoAuthenticate.jspa --output auth.html
echo Copying project...
curl -s -b "$COOKIES" -H "$HEADER" -d "os_cookie=true" -d "webSudoIsPost=true" -d "cannedScript=com.onresolve.jira.groovy.canned.admin.CopyProject" -d "cannedScriptArgs_FIELD_SOURCE_PROJECT=OLD_PROJECT_KEY" -d "cannedScriptArgs_FIELD_TARGET_PROJECT=NEW_PROJECT_KEY" -d "cannedScriptArgs_FIELD_TARGET_PROJECT_NAME=New Project Name" -d "RunCanned=Run" --output output.html $JIRA_URL/secure/admin/groovy/CannedScriptRunner.jspa
echo Cleaning up...
rm $COOKIES
The problem is, I save this as a *.sh file and try to run it on the same server as Jira server installation that has the ScriptRunner add on and it does not work. I initially get the error
-bash: ./scriptrunner.sh: /bin/bash^M: bad interpreter: No such file or directory
I then remove the #!/bin/bash and the result is below:
[root@TEST-PROJECT1 scripts]# ./scriptrunner.sh
./scriptrunner.sh: line 6: $'\r': command not found
Logging in...
./scriptrunner.sh: line 9: $'\r': command not found
Authenticating as administrator...
./scriptrunner.sh: line 12: $'\r': command not found
Copying project...
./scriptrunner.sh: line 15: $'\r': command not found
Cleaning up...
rm: cannot remove 'cookies.txt'$'\r': No such file or directory
I'm not particularly experienced, but I can't figure out what I am doing wrong?
Can anyone help please?