Create Build in Jenkins by using command line with ssh - linux

I hope you're doing well,
I'm traying to automate a Jenkins process using a bash script in Linux, in which I need to create a build, then with created build I need to create a build using the option "Build with parameters" and use a specific build to create it.
First I'm creating the build with a similar command (it is corking fine it created the build successfully):
ssh -l MyUser -p JENK_PORT JENK_SERver build job-build -s –v
it creates the build number 10 then I need to use this build to create another one for the job job-deploy, something like:
ssh -l MyUser -p JENK_PORT JENK_SERver build job-deploy -p COPY_PROMOTION_LEVEL=1 -p BUILD_SELECTOR="\<SpecificBuildSelector plugin=\"copyartifact#1.37\"\> \<buildNumber\>10 \</buildNumber\>\</SpecificBuildSelector\>" -s -v
when I ran it, I'm getting this error:
ERROR: Too many arguments: plugin=copyartifact#1.37>
If I change the "space" for &nbsp/&#032 or adding a back slash between SpecificBuildSelector and plugin=copyartifact#1.37, I got this error:
ERROR: Unexpected exception occurred while performing build command.
com.thoughtworks.xstream.io.StreamException: : only whitespace
content allowed before start tag and not \ (position: START_DOCUMENT
seen ... #1:1)
Do you know how can I do it??, create the build for an specific build in the command line by passing the build parameters with -p option?
Thanks in advance.

Related

Docker - unable to run script

What I'm doing
I am using AWS batch to run a docker container for a large compute job. I have configured the ECR/ECS successfully to the best of my knowledge but am having issues running the required commands for reasons that are beyond my level of understanding with docker ( newbie )
What I need to do is pass the below commands into my application and start my application to perform some heavy computing tasks; all commands listed below must be present.
The Issue(s)
The issue arises when I send the submit job to AWS batch; this service pulls the image from the ACR ( amazon container repository ) and spins up a compute environment. The issue comes from when I try to run the command I pass in, below I will go throgh it.
"command": [
"mkdir -p logging",
"chmod 777 logging/",
"docker run -t -i -e my-application", # container name
"-e APIKEY",
"-e BASEURI",
"-e APIUSER",
"-v WORKSPACE /logging:/src/log",
"DOCKERIMAGE",
"python my_app.py",
"-t APP_USER",
"-e APP_ENVIRONMENT",
"-u APP_USERNAME",
"-p APP_PASSWORD",
"-i IN_PATH",
"-o OUT_PATH",
"-b tmp/"
]
The command above generates the following error(s)
container_linux.go:370: starting container process caused: exec: "mkdir -p log": executable file not found in $PATH
I tried to pass in the command to echo the env var $PATH but was unsuccesfull getting a response and resulted in a similar error.
I have ran successfully "ls" and was able to see the directory contents of my application inside.
I am not however able to run any of these commands that I have included in the command [] section. I have tried just running python and such in hopes of getting a more detailed error but was unsuccessful.
Logic in plain English
Create a path called logging if it doesnt exist
set the permissions for logging
run the docker container and pass in the environment variables while doing so
Tell docker to run the python file my_app.py and pass in the expected runtime args
Execute and perform the required logic deligated in the python3 application
Questions
Why can I not create a directory here called "logging" where am I ?
Am I running these properly as defined by AWS batch? or docker
What am I missing or where am I going wrong?
AWS Batch high level doc
AWS Batch link specific to what i'm doing
Assuming that you're following the syntax described in the Container
Properties
section of the AWS docs, you have several problems with the syntax of
your command directive.
First
The command directive can only run a single command. You can't mash together a bunch of commands as you're trying to do in your example. If you need to run multiple commands you would need to embed them as an argument to a shell. For example, something like:
command: ["/bin/sh", "-c", "mkdir -p logging; chmod 777 logging; ..."]
Second
You must properly tokenize your
command lines -- that is, when you type mkdir -p logging at the
command prompt, the shell splits this into three parts (or "tokens"): ['mkdir', '-p', 'logging']. You need to do the same thing when building up the
list of arguments to command.
This is invalid:
command: ["mkdir -p logging"]
That would looking for a command named mkdir -p logging, and of course no such command exists. That would properly be written as:
command: ["mkdir", "-p", "logging"]
Third
I'm not very familiar with the AWS batch environment, but it's unlikely you can run a docker command inside a docker` container as you're trying to do. It's unclear why you're doing this, though: why not just configure your AWS batch job with the appropriate image, environment variables, etc?
Take a look at some of these example job definitions.

gitlab API to download archive file in git gives bad file but good when called from local machine

I'm trying to retrieve a build file using the gitlab API. This file was created and stored as an artifact from an upstream pipeline. Running
curl -o download --location --header 'PRIVATE-TOKEN:{MY_API_TOKEN}' https://gitlab.foo.com/api/v4/projects/{PROJECT_ID}/jobs/artifacts/{REF_BRANCH}/download?job={JOB_NAME}
on my local machine gives me a proper build file once I run unzip download. However in the runner, the same command returns a much smaller file which I can't unzip. I've checked that the environment variables that are passed in the runner are right.
job in .gitlab-ci.yml
deploy_production_environment:
stage: deploy_prod
image:
name: banst/awscli
script:
- apk --no-cache add curl
- apk add unzip
- echo $JOB_ID
- echo $FE_BUILD_TOKEN
- echo "https://gitlab.foo.com/api/v4/projects/${PROJECT_ID}/jobs/artifacts/${CI_COMMIT_REF_NAME}/download?job=build_prod"
- aws configure set region us-east-1
- "curl -o download --location --header 'PRIVATE-TOKEN:${FE_BUILD_TOKEN}' https://gitlab.foo.com/api/v4/projects/${PROJECT_ID}/jobs/artifacts/${CI_COMMIT_REF_NAME}/download?job=build_prod"
- ls -l
- unzip download
- aws s3 cp build s3://$S3_BUCKET_PROD --recursive
gitlab job output:
`
output from my local terminal:
Why does the API call from inside the runner consistently result in this much smaller (corrupted?) file while the same call pulls the zip file down correctly on my local machine?
The first check to do when a curl brings back a "small" file it to read its content.
Often, the file is not so much corrupted but includes a text-based error message in it, which can give a clue as to the actual issue.
Adding -v to the curl command can also help illustrating the issue during the curl process (when executed in the context of the GitLab job).
Thank you to VonC for the debugging help, recommending the -v flag to the curl command. It turns out that the single quotes around 'PRIVATE-TOKEN:${FE_BUILD_TOKEN}' prevented the variable from being parsed to its correct string value which was giving a 401 'Permission Denied' error. Removing the single quotes did the trick.

Docker: Is there a limit to the number of build-arg's you can have?

I'm using Azure pipelines and trying to build a docker image but getting stuck on this error:
"docker build" requires exactly 1 argument.
I have over 20 --build-arg ENV_VAL=$(ENV_VAL) (example), and was thinking maybe its throwing that error because of the number of build args.
Anyone got an idea?
1,It can be caused by the missing of the . at the end of your docker command.
docker build -f MyDockerfile -t proj:myapp .
The . at the end specify the build context to be the current working directory.
2,If the build-args you passed has space in it. It can also cause above error. Please check if the $(ENV_VAL) you passed in the build-args has spaces in it. To avoid this. You can wrap the variables in quotes. See below:
--build-arg ENV_VAL="$(ENV_VAL)"
3,Please also check the format of your docker command, if you copied and pasted your command. There might be some hidden formatting in your command that caused the error.
If you were using docker task in azure pipeline. you can select the Path to Build context. Select ** to set the build context to the folder where the dockerfile resides.
See this, all options including --build-arg is treat as options not arg:
flags.Var(&options.buildArgs, "build-arg", "Set build-time variables")
So, for docker build, only one arg needed, it's build context, see this:
options.context = args[0]
And the error "docker build" requires exactly 1 argument. comes from here, means you did not specify build context, not related to --build-arg.

starting container process caused "exec: > \"exec\": executable file not found in $PATH": unknown

I have this Dockerfile:
FROM 939fj39f3932.dkr.ecr.us-west-2.amazonaws.com/teros_keys:8e31674
WORKDIR /zoom
COPY app.sh .
ENTRYPOINT ["exec", "/zoom/app.sh"]
CMD []
I build it and it works fine. Then I run it with:
docker run --rm -d \
-e "db_prefix=$db_prefix" \
--name "$n" "$full_name"
and I get this error:
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:345: starting container process caused "exec:
\"exec\": executable file not found in $PATH": unknown.
anyone know what's up with that?
I changed it to:
ENTRYPOINT ["bash", "/zoom/app.sh"]
and it worked, dunno why tho
When you use the JSON-array form of ENTRYPOINT (or CMD or RUN), the command is run exactly as-is. There is no shell handling at all. exec, though, is what the standard refers to as a "special built-in utility"; it only exists within the context of a shell. Docker winds up looking for a /bin/exec or /usr/bin/exec tool, and it's not there, yielding that error message.
If you can just run the script as is (it's executable and has a correct "shebang" line #!/bin/sh or similar) then you don't need a modifier like exec. You can just specify it directly
# No ENTRYPOINT
CMD ["/zoom/app.sh"]
In my case, the issue is I tried to use like this CMD ["ls -a"].
resolution:
changed to CMD ["ls", "-a"]

Docker invalid tag value

I'm trying to build the OwnCloud desktop client, for which the Owncloud docs explain that docker should be used:
Assuming you are in the root of the ownCloud Client’s source tree, you
can build an image from this Dockerfile like this:
cd admin/win32/docker
docker build . -t ownCloud-client-win32:<version>
I get an error with this exact command, so following the docker build docs I moved the dot to the end. But then I get the following error:
$ docker build -t ownCloud-client-win32:2.1 .
invalid value "ownCloud-client-win32:2.1" for flag -t: Error parsing reference: "ownCloud-client-win32:2.1" is not a valid repository/tag
See 'docker build --help'.
Why is ownCloud-client-win32:2.1 not a valid tag name?
I then just tried running docker build ., which runs successfully, but then I end up with an untagged image.
Does anybody have any idea how I can solve this?
ps. I don't know if it's important, but the relevant Dockerfile is here.
No uppercase. Try: owncloud-client-win32:2.1

Resources