Script Module Not Recognized

I wrote a script module in powershell. When I call it from a custom script step using powershell, or a custom step that does the same thing using powershell I am unable to resolve it as a reference.

I’ve tried the Import-Module approach, and based on the documentation here: https://octopus.com/docs/administration/script-modules
I have created a module that has a couple of parameter inputs, and they are called by name in the code.

in the code I call it like:

replacething -path $path -search $item -replace $theThing -pattern *.doc

Am I calling it wrong?

I found this topic from a year ago that this seems similar to. https://help.octopusdeploy.com/discussions/questions/3440-script-module

Hi,

Thanks for getting in touch! I may need to get a bit more information from you here before I can help. I can not see mention to Import-Module in the documentation for the script-modules, Would you be able to attach some screenshots of how you have this configured? It should help me troubleshoot your issue easier.

Where in Octopus are you experiencing the issue? If it is during a deployment, I will need to get a copy of your deployment logs. https://octopus.com/docs/how-to/get-the-raw-output-from-a-task

Looking forward to hearing from you.

Best regards,
Daniel

This screenshot is the most recent deployment, from when I tried to use "Import-Module in the deployment.

the one titled “octopus module error 2” is the time I tried NOT writing “Import-Module” before my statement.

octopus_module_error.PNG

octopus_module_error_2.PNG

failed deploy log.

failed_octopus_log.txt (12 KB)

Hi Zoren,

Thanks for getting back. The information from the screenshots is a little bit helpful but not quite enough. The following bits of information will help me get a better understanding of what is happening here and how I can help.

Would you be able to give me some information about this script?
It would really help If you could attach the script from the script module to this conversation (I will make it private so only we can see it).
Would you also be able to attach screenshots from inside the step where you are calling functions from the attached script module?
Finally, could you attach a screenshot of the entire deployment process page for this project?

Our Script Modules documentation does not mention of using Import-Module and should not be needed here. The script modules are designed to be added on the deployment process page, which then makes the functions you have made in the script module available in your steps.

If you have any questions here, please let me know.
Looking forward to hearing from you. :slight_smile:

Best regards,
Daniel

Daniel –

The script module takes 4 parameters and is written in this manner:

function replaceoccurences($path, $search, $replace, $fileMatchPattern)
{ script code }

inside of the step that currently uses it, I make multiple calls to the module in this manner:

replaceoccurrences -path $sourceDir -search ‘Application(“UseNewReports”) = “true”’ -replace ‘Application(“UseNewReports”) = “true”’ -fileMatchPattern *.asa

but it always fails on first one. I will also add that the little check box that allows you to use script modules was selected, and it shows up on the main page for the process as an available module.

Edit:

I found out that it recognizes the “say-hello” function, although it gives me weird warnings about unapproved verbs.when I include it in any step.

Not sure how, but the method itself had a typo in the name, thus causing a problem. works just fine