Pass Environment Variable as commnadline arguments to Service Fabric main entry point - azure-service-fabric

I have a guest exe (third party exe) which is being called in Service Fabric App main entry point. This needs few command line parameter which I can get only at runtime. I am thinking to set environment variable on Set up Entry point and pass it as a command line arguments to main entry point.
My question is it possible to pass Environment variable as command line parameter.

Take a look at https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-how-to-specify-environment-variables. It shows how to pass variables to your Service Fabric services.

Related

How can i send values to a Jenkins script?

I have a Jenkins job and in that job the first thing that runs is a powershell script that I want to capture user inputs values and set them as global variables that are used through out the Jenkins job.
Now i want the user to be able to put these values in from their machine and then run the job with these values ?
How can i do this ?
EDIT: In case anybody else finds this answer. Please see the comments below. This should not be used for credentials! As the communication can be secured by TLS, the credentials will still be visible in build logs etc.
You need to check the This project is parameterized checkbox in the settings of your job in Jenkins. Then define the name, type etc.
The given name is already accessible via standard syntax.
In shell script ${nameOfParam} or %nameOfParam (depending on your shell / os).
In pipelines they are also accessible via params.nameOfParam.
You can set these variables via GUI using Build with parameters or via API call http://<JENKINS_URL>/job/<JOB_NAME>/buildWithParameters/nameOfParam=foo
See also: https://www.baeldung.com/ops/jenkins-parameterized-builds
Only thing I quiet don't get from your question is, what you exactly want to do with the powershell script. A pipeline script in Jenkins is executed on a node, so if the job starts it should be running without any user interaction. To set values from the user input as global variables in a powershell script, you already need to have them available within the jenkins node, hence it's nonsense to set them in the powershell script because they are already available.

how to read the session variables with special chars, spaces ect in powershell on target machine task in tfs 2015

We are using Release Management(client/server) for our deployments today and we have both Agent based and vNext Release templates and we have powershell code which takes care of these deployments. Now, we are migrating to the web version of release management in tfs 2015 , we want to use "powershell on target Machine" task to invoke our base script(which then imports other PS modules) which takes care of the deployment.
The problem we are facing is with variables , we need to pass lot of variables to our code , these variables will then be transformed and replace in our config files. these variables have special characters and spaces etc and when we pass these variables in Session variables the deployment is failing because of the spl char or space etc
Is there a way where we can pass the variables to our code with out getting failure.
we have added a inline powershell task to our release which will add all the variables to an xml file and this file will be sitting on build server , then we are adding windows file copy task to move this file to target server one more task powershell on target machine which invokes our base script in which we have updated to read the variables from xml file.
but the problem with this is that we ended up adding 4 tasks in our release to take care of one component in Release Management and some of our releases are quite complicated where we have ~20 components and if we have to migrate this to web based release management we have to add ~80 steps which will add lot of confusion.
is there a better way of doing this?
Please let me know if i make any sense or if more details are required
Variables screeshot
attached a screenshot of the variables which i am trying to pass to session variables in powershell on target machine task.
these variables has '=' in them and when these are passed to the task i get the following error "2019-02-11T17:11:19.9812595Z ##[error]The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Found value 'Source' with no corresponding key"
we were going in the wrong direction of reading the variables through session variables
we have found out that there is an api which makes all the release variables available.
https://{tfsurl}/{collection}/{project}/_apis/release/releases/{releaseId}?api-version=3.0-preview.1
we have then updated our code to get the variables based on the environment

How to run a powershell script on Amazon EC2 instance at Startup?

I have to think this is a solved issue but I am just not getting it to work. So I have come to you StackOverflow with this issue:
I have a windows server 2016 machine running in amazon ec2. I have a machine.ps1 script in a config directory.
I create an image of the box. (I have tried with checking noreboot and unchecking it)
When I create a new instance of the image I want it to run machine.ps1 at launch to set the computer name and then set routes and some config settings for the box. The goal is to do this without logging into the box.
I have read and tried:
Running Powershell scripts at Start up
and used this to ensure user data was getting passed in:
EC2 Powershell Launch Tools
I have tried setting up a scheduled task that runs the machine.ps1 on start up (It just hangs)
I see the initializeInstance.ps1 on start up task and have tried to even coop that replacing the line to run userdata with the line to run my script. Nothing.
If I log into the box and run machine.ps1, it will restart the computer and set the computer name and then I need to run it once more to set routes. This works manually. I just need to find a way to do it automagically.
I want to launch these instances from powershell not with launch configurations and auto scale.
You can use User data
Whenever you deploy a new server, workstation or virtual machine there is nearly always a requirement to make final changes to the system before it’s ready for use. Typically this is normally done with a post-deployment script that might be triggered manually on start-up or it might be a final step in a Configuration Manager task sequence or if you using Azure you may use the Custom Script Extension. So how do you achieve similar functionality using EC2 instances in Amazon Web Services (AWS)? If you’ve created your own Amazon Machine Image (AMI) you can set the script to run from the Runonce registry key, but then can be a cumbersome approach particularly if you want to make changes to the script and it’s been embedded into the image. AWS offers a much more dynamic method of injecting a script to run upon start-up through a feature called user data.
Please refer following link for ther same:
Poershell User data
Windows typically won't let a powershell script call another powershell script unless it is being run as Administrator. It is a weird 'safety' feature. But it is perfectly okay to load the ps1 files and use any functions inside them.
The UserData script is typically run as "system". You would THINK that would pass muster. But it fails...
The SOLUTION: Make ALL of your scripts into powershell functions instead.
In your machine.ps1 - wrap the contents with function syntax
function MyDescriptiveName { <original script contents> }
Then in UserData - use the functions like this
# To use a relative path
Set-Location -Path <my location>
# Load script file into process memory
. <full-or-relpath>/machine.ps1
# Call function
MyDescriptiveName <params-if-applicable>
If the function needs to call other functions (aka scripts), you'll need to make those scripts into functions and load the script file into process memory in UserData also.

How to get process information in PowerShell for runtime environment variables?

I want to get all the environment variables for a running process in PowerShell.
I know that I can get such information for startup settings using "Get-Process". If another service adds a variable on runtime these are missing here.
Any suggestions?

Is there a way to use an Env Variable from CCRC to a non-interactive trigger?

I have a (clearcase) preop non-interactive trigger that needs to evaluate an environment variable value (from client side) in order to perform some checks.
Is there a way or w/a to pass such environment variable value from client with CCRC to the trigger, considering it seems to do not work as with dynamic or snapshot view?
Thanks a lot!
According to this IBM article, no. A non-defined environment variable on the server side might cause the trigger to think it is an interactive one.
The trigger script was referencing a user defined environment variable which was set on the client but could not be found on the RWP web server.
In this example the user defined environment variable MYCC_TRIGGER_TMP was set on the client to define an alternate temp directory and is referenced by the trigger script.
However, it was not defined on the RWP web server.
An example of the full error message:
Unable to checkin "<path to file>"
Error: directory for environmentvariable "MYCC_TRIGGER_TMP" or "TMP" not found
ccweb: Warning: Trigger "ci_pre" has refused to let checkin proceed.
Interactive triggers are not supported in the Web interface.
If the trigger was interactive, it may have failed for that reason.
ccweb: Error: Unable to check in "<path to file>".
The article Writing triggers for the ClearCase Remote Client confirms that, albeit indirectly.
Note: Under certain conditions, pre-op triggers will not work (for example, triggers that require specific ClearCase environment variable evaluation).
CCRC runs as a client process that sends RPC commands to the CCRC server, where they are executed by separate CCRC server processes.
These server processes run under Apache, so the environment variables (EVs) will likely be different from those seen in command shell windows during interactive development.
The server config file (rwp.conf, ccrc.conf) can be modified to add environment variables using the SetEnv command.