Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Getting powershell error

I recently installed a new bamboo remote agent and added all the capabilities.  Now when I try to test a simple powershell job in bamboo on that agent, I am getting this error:

Version:1.0 StartHTML:000000244 EndHTML:000000636 StartFragment:000000411 EndFragment:000000598 StartSelection:000000411 EndSelection:000000598 SourceURL:https://bamboo.i.fgvms.com/download/ID-STFNA-JOB1/build_logs/ID-STFNA-JOB1-17.log

Failing task since return code of [powershell -ExecutionPolicy bypass -Command D:\bamboo-agent-home\temp\ID-STFNA-JOB1-17-ScriptBuildTask-8096323714329391444.ps1] was -1 while expected 0

 

3 answers

1 vote
robhit Atlassian Team Apr 05, 2018

Hi Hector,

Thanks for your question!

The bamboo task is failing because the return code of the PowerShell Script is -1 which means error. Bamboo script task works on the return status code returned by the script. So I believe this script will fail even when executed outside Bamboo (on the same machine in the PowerShell Terminal) So if it fails there it will fail in Bamboo also.

You should first test the script in the PowerShell and then configure it in bamboo.

Let me know if it passes locally. Share the code then.

Thanks,

Robhit

Robhit,

 

I am not calling a script.  All I'm doing is typing write-host 'hello' and it fails with that error message.

robhit Atlassian Team Apr 05, 2018

Hi Hector,

I am not quite sure what "write-host 'hello'" command does in Windows. But could you try to execute a simple "echo hello" command using Bamboo?

that is powershell command that doesn't work.  Echo hello works if i'm not using powershell.

Robhit,

my job plan is using a powershell inline command.  all it says is  write-host 'hello'.  one line and it fails.  it should work and return hello.

robhit Atlassian Team Apr 05, 2018

Do you men "echo hello" doesn't work when you use the PowerShell as an interpreter? Which means none of the PowerShell commands works using Bamboo?

Ideally "echo hello" should also work when using PowerShell, Can we try any other command like "wmic"? I am just trying to eliminate the possibilities.

Also, check and confirm of the remote agent is executing the task on the correct Windows machine or not.

Maybe you can attach a full log here when using "wmic" command.

both commands also fail using the powershell interpreter.  attaching the log.

 

simple 05-Apr-2018 15:31:56 Build ALM Tools - Simple Test for New Agents - test #19 (ID-STFNA-JOB1-19) started building on agent EG2-PP-BMB-09.eg2pp.net
simple 05-Apr-2018 15:31:56 Remote agent on host EG2-PP-BMB-09.eg2pp.net
simple 05-Apr-2018 15:31:56 Build working directory is D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1
simple 05-Apr-2018 15:31:56 Executing build ALM Tools - Simple Test for New Agents - test #19 (ID-STFNA-JOB1-19)
simple 05-Apr-2018 15:31:56 Starting task 'Checkout Default Repository' of type 'com.atlassian.bamboo.plugins.vcs:task.vcs.checkout'
simple 05-Apr-2018 15:31:56 Build always requires a clean checkout
simple 05-Apr-2018 15:31:56 Cleaning build directory 'D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1'
simple 05-Apr-2018 15:31:56 Checking out into D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1
simple 05-Apr-2018 15:31:56 Updating source code to revision: 9216ba5a8c0ff9f542ae04c1576dcc1978650845
simple 05-Apr-2018 15:31:56 Creating local git repository in 'D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1\.git'.
simple 05-Apr-2018 15:31:56 Initialized empty Git repository in D:/bamboo-agent-home/xml-data/build-dir/ID-STFNA-JOB1/.git/
simple 05-Apr-2018 15:31:56 Fetching 'refs/heads/master' from 'ssh://git@git.i.fgvms.com/at/adminscripts.git'.
simple 05-Apr-2018 15:31:57 Warning: Permanently added '[127.0.0.1]:50173' (RSA) to the list of known hosts.
simple 05-Apr-2018 15:31:57 From ssh://127.0.0.1:50173/at/adminscripts
simple 05-Apr-2018 15:31:57 * [new branch] master -> master
simple 05-Apr-2018 15:31:57 * [new tag] mytag -> mytag
simple 05-Apr-2018 15:31:57 * [new tag] tag1 -> tag1
simple 05-Apr-2018 15:31:57 * [new tag] tag2 -> tag2
simple 05-Apr-2018 15:31:57 * [new tag] tag3 -> tag3
simple 05-Apr-2018 15:31:57 Checking out revision 9216ba5a8c0ff9f542ae04c1576dcc1978650845.
simple 05-Apr-2018 15:31:57 Already on 'master'
simple 05-Apr-2018 15:31:57 Updated source code to revision: 9216ba5a8c0ff9f542ae04c1576dcc1978650845
simple 05-Apr-2018 15:31:57 Finished task 'Checkout Default Repository' with result: Success
simple 05-Apr-2018 15:31:57 Running pre-build action: Artifactory Release Staging
simple 05-Apr-2018 15:31:57 Running pre-build action: VCS Version Collector
simple 05-Apr-2018 15:31:57 Running pre-build action: Hung Build Killer PreBuildAction
simple 05-Apr-2018 15:31:57 Starting task 'say hello' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
command 05-Apr-2018 15:31:57 Beginning to execute external process for build 'ALM Tools - Simple Test for New Agents - test #19 (ID-STFNA-JOB1-19)'\n ... running command line: \nD:\bamboo-agent-home\temp\ID-STFNA-JOB1-19-ScriptBuildTask-2402193576168522380.bat\n ... in: D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1\n ... using extra environment variables: \nbamboo_planRepository_1_branch=master\nbamboo_capability_system_builder_maven_Artifactory_Maven_3=C:\apache-maven-3.5.2\nbamboo_planRepository_1_branchDisplayName=master\nbamboo_repository_revision_number=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_artifactory_deploy_4_state_staging=False\nbamboo_artifactory_deploy_3_state_smoked=False\nbamboo_resultsUrl=https://bamboo.i.fgvms.com/browse/ID-STFNA-JOB1-19\nbamboo_capability_system_builder_msbuild_MSBuild_v4_0__32bit_=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe\nbamboo_artifactory_deploy_6_state_certified_for_prod=False\nbamboo_repository_58949732_git_branch=master\nbamboo_repository_58949732_revision_number=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_build_working_directory=D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1\nbamboo_planRepository_1_name=AdminScripts\nbamboo_... Test for New Agents\nbamboo_artifactory_deploy_99_state_discarded=False\nbamboo_artifactory_deploy_7_state_released_to_prod=False\nbamboo_planRepository_name=AdminScripts\nbamboo_capability_ADMIN=True\nbamboo_repository_58949732_branch_name=master\nbamboo_buildNumber=19\nbamboo_shortJobName=test\nbamboo_buildResultsUrl=https://bamboo.i.fgvms.com/browse/ID-STFNA-JOB1-19\nbamboo_planRepository_repositoryUrl=ssh://git@git.i.fgvms.com/at/adminscripts.git\nbamboo_agentId=59408392\nbamboo_planName=ALM Tools - Simple Test for New Agents\nbamboo_shortPlanKey=STFNA\nbamboo_shortJobKey=JOB1\nbamboo_planRepository_revision=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_artifactory_deploy_2_state_deployable=False\nbamboo_buildTimeStamp=2018-04-05T15:31:56.410Z\nbamboo_repository_previous_revision_number=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_planRepository_previousRevision=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_repository_git_branch=master\nbamboo_buildResultKey=ID-STFNA-JOB1-19\nbamboo_repository_branch_name=master\nbamboo_almteam=ha83Dhn^ou7C\nbamboo_buildPlanName=ALM Tools - Simple Test for New Agents - test\nbamboo_repository_58949732_git_repositoryUrl=ssh://git@git.i.fgvms.com/at/adminscripts.git\nbamboo_planRepository_1_revision=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_repository_name=AdminScripts\nbamboo_dependenciesDisabled=false\nbamboo_buildFailed=false\nbamboo_feature_build_number=\nbamboo_repository_58949732_name=AdminScripts\nbamboo_deploy_fgdep=mayor.0.SIMPLEton\nbamboo_planRepository_branch=master\nbamboo_agentWorkingDirectory=D:\bamboo-agent-home\xml-data\build-dir\nbamboo_capability_system_git_executable=C:\Program Files\Git\bin\git.exe\nbamboo_repository_git_username=\nbamboo_artifactory_deploy_1_state_compiled=True\nbamboo_planRepository_1_previousRevision=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_planRepository_branchDisplayName=master\nbamboo_planRepository_1_type=bbserver\nbamboo_planRepository_branchName=master\nbamboo_capability_system_jdk_JDK=C:\jdk1.8.0\nbamboo_plan_storageTag=plan-58753227\nbamboo_capability_system_builder_command_Powershell=C:\Windows\System32\WindowsPowerShell\v1.0\nbamboo_capability_system_jdk_JDK_1_8_0_66=C:\jdk1.8.0\nbamboo_artifactory_deploy_5_state_certified_for_beta=False\nbamboo_planRepository_1_username=\nbamboo_planRepository_type=bbserver\nbamboo_ManualBuildTriggerReason_userName=i842625\nbamboo_repository_git_repositoryUrl=ssh://git@git.i.fgvms.com/at/adminscripts.git\nbamboo_capability_system_builder_msbuild_MSBuild_v4_0__64bit_=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe\nbamboo_repository_58949732_previous_revision_number=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_capability_system_builder_mvn3_Maven_3=C:\apache-maven-3.5.2\nbamboo_capability_system_builder_ant_Apache_Ant_1_9_6=C:\apache-ant-1.9.6\nbamboo_working_directory=D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1\nbamboo_planKey=ID-STFNA\nbamboo_planRepository_1_repositoryUrl=ssh://git@git.i.fgvms.com/at/adminscripts.git\nbamboo_planRepository_username=\nbamboo_capability_system_jdk_JDK_1_8=C:\jdk1.8.0\nbamboo_planRepository_1_branchName=master\nbamboo_artifactory_deploy_0_release=TBD\n
build 05-Apr-2018 15:31:58
build 05-Apr-2018 15:31:58 D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1>echo "hello"
build 05-Apr-2018 15:31:58 "hello"
simple 05-Apr-2018 15:31:58 Finished task 'say hello' with result: Success
simple 05-Apr-2018 15:31:58 Starting task 'simple hello' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
command 05-Apr-2018 15:31:58 Beginning to execute external process for build 'ALM Tools - Simple Test for New Agents - test #19 (ID-STFNA-JOB1-19)'\n ... running command line: \nD:\bamboo-agent-home\temp\ID-STFNA-JOB1-19-ScriptBuildTask-8694226943697895162.ps1\n ... in: D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1\n ... using extra environment variables: \nbamboo_planRepository_1_branch=master\nbamboo_capability_system_builder_maven_Artifactory_Maven_3=C:\apache-maven-3.5.2\nbamboo_planRepository_1_branchDisplayName=master\nbamboo_repository_revision_number=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_artifactory_deploy_4_state_staging=False\nbamboo_artifactory_deploy_3_state_smoked=False\nbamboo_resultsUrl=https://bamboo.i.fgvms.com/browse/ID-STFNA-JOB1-19\nbamboo_capability_system_builder_msbuild_MSBuild_v4_0__32bit_=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe\nbamboo_artifactory_deploy_6_state_certified_for_prod=False\nbamboo_repository_58949732_git_branch=master\nbamboo_repository_58949732_revision_number=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_build_working_directory=D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1\nbamboo_planRepository_1_name=AdminScripts\nbamboo_... Test for New Agents\nbamboo_artifactory_deploy_99_state_discarded=False\nbamboo_artifactory_deploy_7_state_released_to_prod=False\nbamboo_planRepository_name=AdminScripts\nbamboo_capability_ADMIN=True\nbamboo_repository_58949732_branch_name=master\nbamboo_buildNumber=19\nbamboo_shortJobName=test\nbamboo_buildResultsUrl=https://bamboo.i.fgvms.com/browse/ID-STFNA-JOB1-19\nbamboo_planRepository_repositoryUrl=ssh://git@git.i.fgvms.com/at/adminscripts.git\nbamboo_agentId=59408392\nbamboo_planName=ALM Tools - Simple Test for New Agents\nbamboo_shortPlanKey=STFNA\nbamboo_shortJobKey=JOB1\nbamboo_planRepository_revision=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_artifactory_deploy_2_state_deployable=False\nbamboo_buildTimeStamp=2018-04-05T15:31:56.410Z\nbamboo_repository_previous_revision_number=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_planRepository_previousRevision=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_build_commandline_com_atlassian_bamboo_plugins_scripttask_task_builder_script_2=D:\bamboo-agent-home\temp\ID-STFNA-JOB1-19-ScriptBuildTask-2402193576168522380.bat\nbamboo_repository_git_branch=master\nbamboo_buildResultKey=ID-STFNA-JOB1-19\nbamboo_repository_branch_name=master\nbamboo_almteam=ha83Dhn^ou7C\nbamboo_buildPlanName=ALM Tools - Simple Test for New Agents - test\nbamboo_repository_58949732_git_repositoryUrl=ssh://git@git.i.fgvms.com/at/adminscripts.git\nbamboo_planRepository_1_revision=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_repository_name=AdminScripts\nbamboo_dependenciesDisabled=false\nbamboo_buildFailed=false\nbamboo_feature_build_number=\nbamboo_repository_58949732_name=AdminScripts\nbamboo_deploy_fgdep=mayor.0.SIMPLEton\nbamboo_planRepository_branch=master\nbamboo_agentWorkingDirectory=D:\bamboo-agent-home\xml-data\build-dir\nbamboo_capability_system_git_executable=C:\Program Files\Git\bin\git.exe\nbamboo_repository_git_username=\nbamboo_artifactory_deploy_1_state_compiled=True\nbamboo_planRepository_1_previousRevision=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_planRepository_branchDisplayName=master\nbamboo_planRepository_1_type=bbserver\nbamboo_planRepository_branchName=master\nbamboo_capability_system_jdk_JDK=C:\jdk1.8.0\nbamboo_plan_storageTag=plan-58753227\nbamboo_capability_system_builder_command_Powershell=C:\Windows\System32\WindowsPowerShell\v1.0\nbamboo_capability_system_jdk_JDK_1_8_0_66=C:\jdk1.8.0\nbamboo_artifactory_deploy_5_state_certified_for_beta=False\nbamboo_planRepository_1_username=\nbamboo_planRepository_type=bbserver\nbamboo_ManualBuildTriggerReason_userName=i842625\nbamboo_repository_git_repositoryUrl=ssh://git@git.i.fgvms.com/at/adminscripts.git\nbamboo_capability_system_builder_msbuild_MSBuild_v4_0__64bit_=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe\nbamboo_repository_58949732_previous_revision_number=9216ba5a8c0ff9f542ae04c1576dcc1978650845\nbamboo_capability_system_builder_mvn3_Maven_3=C:\apache-maven-3.5.2\nbamboo_capability_system_builder_ant_Apache_Ant_1_9_6=C:\apache-ant-1.9.6\nbamboo_working_directory=D:\bamboo-agent-home\xml-data\build-dir\ID-STFNA-JOB1\nbamboo_planKey=ID-STFNA\nbamboo_planRepository_1_repositoryUrl=ssh://git@git.i.fgvms.com/at/adminscripts.git\nbamboo_planRepository_username=\nbamboo_capability_system_jdk_JDK_1_8=C:\jdk1.8.0\nbamboo_planRepository_1_branchName=master\nbamboo_artifactory_deploy_0_release=TBD\n
simple 05-Apr-2018 15:31:58 Failing task since return code of [powershell -ExecutionPolicy bypass -Command D:\bamboo-agent-home\temp\ID-STFNA-JOB1-19-ScriptBuildTask-8694226943697895162.ps1] was -1 while expected 0
simple 05-Apr-2018 15:31:58 Finished task 'simple hello' with result: Failed
simple 05-Apr-2018 15:31:58 Running post build plugin 'Docker Container Cleanup'
simple 05-Apr-2018 15:31:58 Running post build plugin 'NCover Results Collector'
simple 05-Apr-2018 15:31:58 Running post build plugin 'Artifactory Release Management Staging'
simple 05-Apr-2018 15:31:58 Running post build plugin 'Artifactory Build Info Copier'
simple 05-Apr-2018 15:31:58 Running post build plugin 'Artifactory Gradle Properties Info Copier'
simple 05-Apr-2018 15:31:58 Running post build plugin 'Clover Results Collector'
simple 05-Apr-2018 15:31:58 Running post build plugin 'npm Cache Cleanup'
simple 05-Apr-2018 15:31:58 Running post build plugin 'Artifact Copier'
simple 05-Apr-2018 15:31:58 Finalising the build...
simple 05-Apr-2018 15:31:58 Stopping timer.
simple 05-Apr-2018 15:31:58 Build ID-STFNA-JOB1-19 completed.
simple 05-Apr-2018 15:31:58 Running on server: post build plugin 'NCover Results Collector'
simple 05-Apr-2018 15:31:58 Running on server: post build plugin 'Build Hanging Detection Configuration'
simple 05-Apr-2018 15:31:58 Running on server: post build plugin 'Clover Delta Calculator'
simple 05-Apr-2018 15:31:58 Running on server: post build plugin 'Maven Dependencies Postprocessor'
simple 05-Apr-2018 15:31:58 All post build plugins have finished
simple 05-Apr-2018 15:31:58 Generating build results summary...
simple 05-Apr-2018 15:31:58 Saving build results to disk...
simple 05-Apr-2018 15:31:58 Logging substituted variables...
simple 05-Apr-2018 15:31:58 Indexing build results...
simple 05-Apr-2018 15:31:58 Finished building ID-STFNA-JOB1-19.

I have also confirmed that the command is being executed on that agent because I dedicated that agent to run that script.  By the way,  the script does not fail on all agents. It only fails for one agent.  This is a new agent that I recently activated and it runs on Windows Core.

0 votes
Minh Tran Atlassian Team Apr 05, 2018

@Hector Magnanao Can you try to write a very simple powershell script like printing something to the console and see if that works?

Hi Minh,

all i'm doing is write-host 'Hello' and it fails with that error.

Minh Tran Atlassian Team Apr 05, 2018

Did you configure the requirement to use a Windows OS?

yes, this is a Windows OS.

Minh Tran Atlassian Team Apr 05, 2018

Can you try to run your shell script on your local Windows to see if it works?

It runs fine in windows local.  By the way, the OS is Windows Core.

I found out some interesting things while trying find a solution.  If I create the script using the shell interpreter and calling the powershell executable like this:  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe write-host 'hello'  --- this works  !!!!  But if I use the windows powershell as the interpreter directly, it fails !!!

Hector, Did you ever find a real solution to this problem?  We've got the same issue in Bamboo 6.6.2 if we use the Atlassian script task but if we use a 3rd party PowerShell plugin it works just fine... so the issue is definitely the Atlassian Script task.

Failing task since return code of [powershell -NonInteractive -ExecutionPolicy bypass -Command D:\builds\1\ABC-123\DevOpsScripts\v1\GetAppNameAndVersion.ps1 -Prefix ABC] was -1 while expected 0

Yes,  this is already resolved.  It resolved itself when I was able to correct the path for the bamboo service account.

For those who are wondering, I also had this issue on a Windows 2016 box, with bamboo agent running as a non-interactive service, using the java wrapper.exe. On that machine, the system %PATH% was not being loaded for a domain user account which was being used to run the service. I got things working by modifying the wrapper.conf (referenced on the command line for the win service) to include the following lines:

set.default.MYPATH=%PATH%%WRAPPER_PATH_SEPARATOR%C:\Windows\System32\WindowsPowerShell\v1.0\%WRAPPER_PATH_SEPARATOR%
set.PATH=%MYPATH%

These statements should be on two lines. I used a temporary variable due to a bug mentioned in https://wrapper.tanukisoftware.com/doc/english/props-envvars.html

This may be a hack. I'm not sure what the proper way of injecting the system PATH into a service context is, if any, 

Like APACIT Chubb likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 7.1 is here and is packed with value!

I'm happy to announce that Bamboo 7.1 has been released and it’s overflowing with awesome new features. Top-voted issues First and foremost, a bunch of JAC top voted issues has been delivered - y...

653 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you