PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label bitbucket-pipelines. Show all posts
Showing posts with label bitbucket-pipelines. Show all posts

Sunday, November 13, 2022

[FIXED] How to invoke Plesk Git extension webhook via cURL from Bitbucket Pipelines?

 November 13, 2022     bitbucket, bitbucket-pipelines, git, plesk     No comments   

Issue

Unfortunately, Bitbucket doesn't support per-branch webhooks and won't support them in the near future (https://bitbucket.org/site/master/issues/11728/trigger-webhook-only-for-push-to-specific).

So I thought I maybe could write a simple bitbucket-pipelines.yml which calls the corresponding webhook:

pipelines:
  branches:
    staging:
      - step:
          script:
            - curl $WEBHOOK_STAGING
    master:
      - step:
          script:
            - curl $WEBHOOK_PRODUCTION

Simply requesting the webhook, doesn't seem to trigger a git pull within Plesk, so I'm assuming that I need to add a payload.

Question: What do I need to send to the Plesk webhook in order to perform a pull?


Solution

Webhooks are done via a POST request instead of a GET request, so you will have to pass the argument -X POST to curl in order to send the request to your webhook correctly.

So your curl statement would look like this:

curl -X POST $WEBHOOK_PRODUCTION


Answered By - Sven Hakvoort
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, September 27, 2022

[FIXED] How to deploy the content of dist folder to the server root?

 September 27, 2022     angular6, bitbucket-pipelines, continuous-deployment     No comments   

Issue

I want to deploy all the files from dist folder to one of my folder in the server.

My bitbucket repository name is "test-project-app".

This is the script I have to deploy the application to the server.

script: # The script below will deploy the application to the webserver.
  - apt-get update
  - apt-get install ncftp
  - ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST $FTP_SITE_ROOT dist/*

These are my Repository variables

FTP_HOST: xxx.xxx.xxx.xxx
FTP_SITE_ROOT /public_html/test/

The above script automatically created folder "test-project-app" inside the test folder that contains all the files of dist folder. I want to deploy files of folder to test root.

How can I fix this?

Any help please. Thank You.


Solution

I had encountered the same issue before. Can you change

dist/*

into

dist/**/*

Hope this works for you.



Answered By - nas
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to pass the correct project path to bitbucket pipeline?

 September 27, 2022     amazon-web-services, aws-lambda, bitbucket, bitbucket-pipelines, continuous-deployment     No comments   

Issue

I want to deploy aws lamda .net core project using bit bucket pipeline

I have created bitbucket-pipelines.yml like below but after build run getting error -

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

file code -

image: microsoft/dotnet:sdk

pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script: # Modify the commands below to build your repository.
          - export PROJECT_NAME=TestAWS/AWSLambda1/AWSLambda1.sln
          - dotnet restore
          - dotnet build $PROJECT_NAME
          - pipe: atlassian/aws-lambda-deploy:0.2.1
            variables:
              AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
              AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
              AWS_DEFAULT_REGION: 'us-east-1'
              FUNCTION_NAME: 'my-lambda-function'
              COMMAND: 'update'
              ZIP_FILE: 'code.zip'

project structure is like this -

enter image description here


Solution

The problem is here:

PROJECT_NAME=TestAWS/AWSLambda1/AWSLambda1.sln

This is the incorrect path. Bitbucket Pipelines will use a special path in the Docker image, something like /opt/atlassian/pipelines/agent/build/YOUR_PROJECT , to do a Git clone of your project.

You can see this when you click on the "Build Setup" step in the Pipelines web console:

Cloning into '/opt/atlassian/pipelines/agent/build'...

You can use a pre-defined environment variable to retrieve this path: $BITBUCKET_CLONE_DIR , as described here: https://support.atlassian.com/bitbucket-cloud/docs/variables-in-pipelines/

Consider something like this in your yml build script:

script:
  - echo $BITBUCKET_CLONE_DIR # Debug: Print the $BITBUCKET_CLONE_DIR
  - pwd # Debug: Print the current working directory
  - find "$(pwd -P)" -name AWSLambda1.sln # Debug: Show the full file path of AWSLambda1.sln

  - export PROJECT_NAME="$BITBUCKET_CLONE_DIR/AWSLambda1.sln"
  - echo $PROJECT_NAME
  - if [ -f "$PROJECT_NAME" ]; then echo "File exists" ; fi

  # Try this if the file path is not as expected
  - export PROJECT_NAME="$BITBUCKET_CLONE_DIR/AWSLambda1/AWSLambda1.sln"
  - echo $PROJECT_NAME
  - if [ -f "$PROJECT_NAME" ]; then echo "File exists" ; fi


Answered By - Mr-IDE
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, September 26, 2022

[FIXED] How to populate a parameter file on bitbucket pipelines

 September 26, 2022     bitbucket-pipelines, continuous-deployment, continuous-integration, symfony     No comments   

Issue

I have to populate a parameters.yml file with variables in my pipeline. This is about 60 lines required in the file. So I tried using about 60 echo statements to populate the file, and keep it easily configurable, but when using the validator, it says my pipelines file is invalid because I need to use either a string or a pipe.

Is there another option that would let me echo a multi-line string to a file, or an other option to populate that file with environment variables?

This is how I tried it now:

pipelines:
  default:
    - step:
        name: install and test
        caches:
          - composer
          - node
          - vendor
        script:
          - npm install
          - npm install -g gulp
          - echo "parameters:" > app/config/parameters.yml
          - echo "    database_driver: pdo_mysql" >> app/config/parameters.yml
          - echo "    database_host: $DB_HOST" >> app/config/parameters.yml
          - echo "    database_port: $DB_PORT" >> app/config/parameters.yml
          - echo "    database_name: $DB_NAME" >> app/config/parameters.yml
          - echo "    database_user: $DB_USER" >> app/config/parameters.yml
          - echo "    database_password: $DB_PASS" >> app/config/parameters.yml
          - echo "    redis.dsn.cache: \"$REDIS\"/0" >> app/config/parameters.yml
          - echo "    redis.dsn.doctrine: \"$REDIS/1\"" >> app/config/parameters.yml
          - echo "    redis.dsn.session: \"$REDIS/2\"" >> app/config/parameters.yml
          - echo "    mailer_transport: $MAIL_TRANSPORT" >> app/config/parameters.yml
          - echo "    mailer_host: $MAIL_HOST" >> app/config/parameters.yml
          - echo "    mailer_user: $MAIL_USER" >> app/config/parameters.yml
          - echo "    mailer_password: $MAIL_PASS" >> app/config/parameters.yml
          - echo "    mailer_port: $MAIL_PORT" >> app/config/parameters.yml

Solution

I think the validator had some issues with me echo-ing yaml in the configuration. This is how I fixed it:

pipelines:
  default:
    - step:
        name: install and test
        caches:
          - composer
          - node
          - vendor
        script:
          - npm install
          - npm install -g gulp
          - echo "parameters:" > app/config/parameters.yml
          - echo "    database_driver:\ pdo_mysql" >> app/config/parameters.yml
          - echo "    database_host:\ $DB_HOST" >> app/config/parameters.yml
          - echo "    database_port:\ $DB_PORT" >> app/config/parameters.yml
          - echo "    database_name:\ $DB_NAME" >> app/config/parameters.yml
          - echo "    database_user:\ $DB_USER" >> app/config/parameters.yml
          - echo "    database_password:\ $DB_PASS" >> app/config/parameters.yml
          - echo "    redis.dsn.cache:\ \"$REDIS/0\"" >> app/config/parameters.yml
          - echo "    redis.dsn.doctrine:\ \"$REDIS/1\"" >> app/config/parameters.yml
          - echo "    redis.dsn.session:\ \"$REDIS/2\"" >> app/config/parameters.yml
          - echo "    mailer_transport:\ $MAIL_TRANSPORT" >> app/config/parameters.yml
          - echo "    mailer_host:\ $MAIL_HOST" >> app/config/parameters.yml
          - echo "    mailer_user:\ $MAIL_USER" >> app/config/parameters.yml
          - echo "    mailer_password:\ $MAIL_PASS" >> app/config/parameters.yml
          - echo "    mailer_port:\ $MAIL_PORT" >> app/config/parameters.yml
          - sed -i 's/\\ / /g' app/config/parameters.yml

Basically I couldn't echo valid yaml, so I fixed it using sed to modify the file so the yaml became valid.



Answered By - Pjetr
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, August 21, 2022

[FIXED] What is the best way to load environment variables in your build

 August 21, 2022     bitbucket, bitbucket-pipelines, environment-variables, npm, webpack     No comments   

Issue

For a project I am working on I am setting up a BitBucket pipeline. Everything works great except for the environment vars. One of the usages of my env vars is the API_URL. I am loading the url by using process.env.API_URL. Locally this works great since it loads the .env file by using dotenv-webpack. However, in the pipeline I don't know what the best way is to load these vars. Should I add all the vars to Bitbucket and add export API_URL=$API_URL for every var in the pipeline file or are there better ways to load the vars?


Solution

Workspace, Repository, and Deployment variables is the way to go. Which one you need depends on scope you'd like these variables to cover (naming is pretty self-explanatory: some variables shouldn't change their values across your entire account; others only make sense to a particular repository; finally, some values are specific to a deployment environment).

Just define the variables in the Bitbucket UI or using API, and refer to their values from bitbucket-pipelines.yml or any script that you invoke from it. You don't need to add any export statements. Here's a very good doc explaining the details - https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/ - and User-defined variables section is particularly relevant to your question.

Alternatively, if you committed your .env file, you can simply export its contents all at once as per this StackOverflow answer.

Obviously, don't commit .env if it contains any sensitive values.



Answered By - esimonov
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, January 21, 2022

[FIXED] Is it possible to use composer's archive feature to compress a project locally?

 January 21, 2022     bitbucket, bitbucket-pipelines, composer-php, php     No comments   

Issue

Is it possible to use composer's archive feature to compress a project locally (similar to using zip)? For instance, I tried composer archive my-repo/project --format=zip --file test-archive. It worked in the sense that it created a zip file called test-archive, but composer did it by first going to my satis repo and pulling down a copy of the project.

I also have this defined in my composer.json

"archive": {
        "exclude": [
            ".*",
            "!.gitignore",
            "node_modules/",
            "vendor/",
            "www/",
            "composer/",
            "*.lst",
            "*.yml"
        ]
    }

What I'm trying to do is use the archive feature as part of a bitbucket pipelines build process. The goal is to compress the project files (excluding some) and pass them to the Downloads page for the bitbucket repo. I have a working step using zip, but archive uses a better syntax for excluding files.


Solution

Ok - now I feel a little silly, but since someone kindly upvoted the question, I'll answer it. The documentation was slightly confusing to me. Composer doesn't actually need my-repo/project to compress the file correctly. So if you do composer archive --format=zip --file test-archive it will compress in place at the root of your project.



Answered By - aberkow
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing